|
20 | 20 | import numpy as np
|
21 | 21 | import pygmt
|
22 | 22 |
|
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]) |
26 | 26 |
|
27 | 27 | 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"') |
29 | 29 |
|
30 | 30 | # Plot the line using the default line style
|
31 | 31 | 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 just like a railway track (black/white) |
| 48 | +y -= 1 |
| 49 | +for linestyle in ["5p,black", "4p,white,20p_20p"]: |
| 50 | + fig.plot(x=x, y=y, pen=linestyle) |
| 51 | +fig.text(x=x[-1], y=y[-1], text="5p,black", justify="ML", offset="0.2c/0.2c") |
| 52 | +fig.text(x=x[-1], y=y[-1], text="4p,white,20p_20p", justify="ML", offset="0.2c/-0.2c") |
41 | 53 |
|
42 | 54 | fig.show()
|
0 commit comments