|
| 1 | +""" |
| 2 | +Line segment caps and joints |
| 3 | +============================ |
| 4 | +PyGMT offers different appearances of line segment caps and joints. The desired |
| 5 | +appearance can be set via the GMT default parameters :gmt-term:`PS_LINE_CAP` |
| 6 | +(``"butt"``, ``"round"``, or ``"square"`` [Default]) as well as :gmt-term:`PS_LINE_JOIN` |
| 7 | +(``"bevel"``, ``"round"``, and ``"miter"`` [Default]) and :gmt-term:`PS_MITER_LIMIT` |
| 8 | +(limit on the angle at the mitered joint below which a bevel is applied). |
| 9 | +""" |
| 10 | + |
| 11 | +# %% |
| 12 | +import numpy as np |
| 13 | +import pygmt |
| 14 | + |
| 15 | +# Set up dictionary for colors |
| 16 | +dict_col = { |
| 17 | + "round": "green4", |
| 18 | + "square": "steelblue", |
| 19 | + "butt": "orange", |
| 20 | + "miter": "steelblue", |
| 21 | + "bevel": "orange", |
| 22 | +} |
| 23 | + |
| 24 | +# Create new Figure instance |
| 25 | +fig = pygmt.Figure() |
| 26 | + |
| 27 | +# ----------------------------------------------------------------------------- |
| 28 | +# Top: PS_LINE_CAP |
| 29 | + |
| 30 | +# Create sample data |
| 31 | +x = np.array([30, 170]) |
| 32 | +y = np.array([70, 70]) |
| 33 | + |
| 34 | +fig.basemap(region=[0, 260, 0, 100], projection="x1p", frame="rltb") |
| 35 | + |
| 36 | +for line_cap in ["butt", "round", "square"]: |
| 37 | + # Change GMT default locally |
| 38 | + with pygmt.config(PS_LINE_CAP=line_cap): |
| 39 | + color = dict_col[line_cap] |
| 40 | + # Draw a 10-point thick line with 20-point long segments and gaps |
| 41 | + # Use the local PS_LINE_CAP setting |
| 42 | + fig.plot(x=x, y=y, pen=f"10p,{color},20_20") |
| 43 | + |
| 44 | + # Draw a 1-point thick black solid line to highlight segment cap appearance |
| 45 | + fig.plot(x=x, y=y, pen="1p,black,solid") |
| 46 | + # Plot data points as circles |
| 47 | + fig.plot(x=x, y=y, style="c0.1c", fill="white", pen="0.5p,") |
| 48 | + # Add label for PS_LINE_CAP setting |
| 49 | + fig.text(text=line_cap, x=x[-1] + 20, y=y[-1], justify="LM") |
| 50 | + |
| 51 | + y = y - 20 |
| 52 | + |
| 53 | +fig.shift_origin(yshift="-h") |
| 54 | + |
| 55 | +# ----------------------------------------------------------------------------- |
| 56 | +# Bottom: PS_LINE_JOIN and PS_MITER_LIMIT |
| 57 | + |
| 58 | +x = np.array([5, 95, 65]) |
| 59 | +y = np.array([10, 70, 10]) |
| 60 | + |
| 61 | +fig.basemap(region=[0, 260, 0, 100], projection="x1p", frame="rltb") |
| 62 | + |
| 63 | +for line_join in ["bevel", "round", "miter"]: |
| 64 | + with pygmt.config(PS_LINE_JOIN=line_join, PS_MITER_LIMIT=1): |
| 65 | + color = dict_col[line_join] |
| 66 | + # Draw a 7-point thick solid line |
| 67 | + # Use the local PS_LINE_JOIN and PS_MITER_LIMIT settings |
| 68 | + fig.plot(x=x, y=y, pen=f"7p,{color},solid") |
| 69 | + |
| 70 | + fig.plot(x=x, y=y, pen="1p,black,solid") |
| 71 | + fig.plot(x=x, y=y, style="c0.1c", fill="white", pen="0.5p") |
| 72 | + fig.text(text=line_join, x=x[1] - 10, y=y[1], justify="RB") |
| 73 | + |
| 74 | + x = x + 75 |
| 75 | + |
| 76 | +fig.show() |
0 commit comments