Skip to content

Commit 828ac3e

Browse files
seismanweiji14
andauthored
Improve the gallery example for line styles (#664)
Co-authored-by: Wei Ji <[email protected]>
1 parent 27babbe commit 828ac3e

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

examples/gallery/line/linestyles.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,36 @@
2020
import numpy as np
2121
import pygmt
2222

23-
# Generate a sample line for plotting
24-
x = np.linspace(0, 10, 500)
25-
y = np.sin(x)
23+
# Generate a two-point line for plotting
24+
x = np.array([0, 7])
25+
y = np.array([9, 9])
2626

2727
fig = pygmt.Figure()
28-
fig.basemap(region=[0, 10, -3, 3], projection="X15c/8c", frame=["xaf", "yaf", "WSrt"])
28+
fig.basemap(region=[0, 10, 0, 10], projection="X15c/8c", frame='+t"Line Styles"')
2929

3030
# Plot the line using the default line style
3131
fig.plot(x=x, y=y)
32-
33-
# Plot the lines using different line styles
34-
fig.plot(x=x, y=y + 1.5, pen="1p,red,-")
35-
fig.plot(x=x, y=y + 1.0, pen="2p,blue,.")
36-
fig.plot(x=x, y=y + 0.5, pen="1p,red,-.")
37-
38-
fig.plot(x=x, y=y - 0.5, pen="2p,blue,..-")
39-
fig.plot(x=x, y=y - 1.0, pen="3p,tomato,--.")
40-
fig.plot(x=x, y=y - 1.5, pen="3p,tomato,4_2:2p")
32+
fig.text(x=x[-1], y=y[-1], text="solid (default)", justify="ML", offset="0.2c/0c")
33+
34+
# Plot the line using different line styles
35+
for linestyle in [
36+
"1p,red,-", # dashed line
37+
"1p,blue,.", # dotted line
38+
"1p,lightblue,-.", # dash-dotted line
39+
"2p,blue,..-", # dot-dot-dashed line
40+
"2p,tomato,--.", # dash-dash-dotted line
41+
"2p,tomato,4_2:2p", # A pattern of 4-point-long line segment and 2-point-gap between segment
42+
]:
43+
y -= 1 # Move the current line down
44+
fig.plot(x=x, y=y, pen=linestyle)
45+
fig.text(x=x[-1], y=y[-1], text=linestyle, justify="ML", offset="0.2c/0c")
46+
47+
# Plot the line like a railway track (black/white).
48+
# The trick here is plotting the same line twice but with different line styles
49+
y -= 1 # move the current line down
50+
fig.plot(x=x, y=y, pen="5p,black")
51+
fig.plot(x=x, y=y, pen="4p,white,20p_20p")
52+
fig.text(x=x[-1], y=y[-1], text="5p,black", justify="ML", offset="0.2c/0.2c")
53+
fig.text(x=x[-1], y=y[-1], text="4p,white,20p_20p", justify="ML", offset="0.2c/-0.2c")
4154

4255
fig.show()

0 commit comments

Comments
 (0)