|
| 1 | +--- |
| 2 | +file_format: mystnb |
| 3 | +--- |
| 4 | + |
| 5 | +# Justification codes |
| 6 | + |
| 7 | +To place plot embellishments, such as scalebars, directional roses, colorbars, legends, |
| 8 | +text, or images on a figure, two points have to be specified: a point somewhere on the |
| 9 | +figure (**reference point**) and a point on the feature (**anchor point**). For both, |
| 10 | +users can use a two-character code, a combination of a vertical code and a horizontal |
| 11 | +code (order-independent): |
| 12 | + |
| 13 | +- Vertical: **T**(op), **M**(iddle), **B**(ottom) |
| 14 | +- Horizontal: **L**(eft), **C**(entre), **R**(ight) |
| 15 | + |
| 16 | +For example, `"TL"` means **T**op **L**eft. |
| 17 | + |
| 18 | +The possible nine justification codes are visualized in the sketch below: |
| 19 | + |
| 20 | +```{code-cell} |
| 21 | +--- |
| 22 | +tags: [remove-input] |
| 23 | +--- |
| 24 | +""" |
| 25 | +Script showing the justification codes used in GMT / PyGMT. |
| 26 | +""" |
| 27 | +import pygmt |
| 28 | +
|
| 29 | +size = 5 |
| 30 | +x1 = [-size, 0, size, size, size, 0, -size, -size, 0] |
| 31 | +y1 = [-size, -size, -size, 0, size, size, size, 0, 0] |
| 32 | +codes = ["BL", "BC", "BR", "MR", "TR", "TC", "TL", "ML", "MC"] |
| 33 | +
|
| 34 | +fig = pygmt.Figure() |
| 35 | +fig.basemap(projection="X10c/6c", region=[-size, size, -size, size], frame=0) |
| 36 | +
|
| 37 | +fig.text( |
| 38 | + font="15p,1,black", |
| 39 | + x=x1, |
| 40 | + y=y1, |
| 41 | + text=codes, |
| 42 | + justify=codes, |
| 43 | + offset="j0.5c/0.5c+v2p,gray30", |
| 44 | +) |
| 45 | +
|
| 46 | +fig.plot(x=x1, y=y1, style="c0.3c", fill="steelblue", no_clip=True) |
| 47 | +
|
| 48 | +fig.text( |
| 49 | + font="15p", |
| 50 | + offset="j0.5c/0.5c", |
| 51 | + no_clip=True, |
| 52 | + x=[size, size, size, -size, 0, size], |
| 53 | + y=[size, 0, -size, size, size, size], |
| 54 | + justify=["ML", "ML", "ML", "BC", "BC", "BC"], |
| 55 | + text=[ |
| 56 | + "@%1%T@%%op", |
| 57 | + "@%1%M@%%iddle", |
| 58 | + "@%1%B@%%ottom", |
| 59 | + "@%1%L@%%eft", |
| 60 | + "@%1%C@%%enter", |
| 61 | + "@%1%R@%%ight", |
| 62 | + ], |
| 63 | +) |
| 64 | +
|
| 65 | +fig.show(width=600) |
| 66 | +``` |
| 67 | + |
| 68 | +For a non-rectangular geographic basemap, the justification codes refer to the invisible, |
| 69 | +rectangular map bounding box: |
| 70 | + |
| 71 | +```{code-cell} |
| 72 | +--- |
| 73 | +tags: [remove-input] |
| 74 | +--- |
| 75 | +""" |
| 76 | +Script showing justification codes for non-rectangular geographic basemaps. |
| 77 | +""" |
| 78 | +fig = pygmt.Figure() |
| 79 | +fig.basemap(projection="H10c", region="g", frame=0) |
| 80 | +
|
| 81 | +for code in codes: |
| 82 | + fig.text( |
| 83 | + font="10p,1,black", |
| 84 | + position=code, |
| 85 | + justify=code, |
| 86 | + text=code, |
| 87 | + offset="j0.5c/0.5c+v2p,gray30", |
| 88 | + ) |
| 89 | + fig.text(font="10p,steelblue", position=code, justify="MC", text="●", no_clip=True) |
| 90 | +
|
| 91 | +fig.show(width=600) |
| 92 | +``` |
| 93 | + |
| 94 | + |
| 95 | +Plot embellishments can be abstracted as rectangles. Here, the justification codes are |
| 96 | +shown exemplary for a colorbar. |
| 97 | + |
| 98 | +```{code-cell} |
| 99 | +--- |
| 100 | +tags: [remove-input] |
| 101 | +--- |
| 102 | +""" |
| 103 | +Script showing justification codes for plot embellishments, e.g., a colorbar. |
| 104 | +""" |
| 105 | +fig = pygmt.Figure() |
| 106 | +fig.basemap(projection="X10c/2c", region=[-size, size, -size, size], frame=0) |
| 107 | +
|
| 108 | +fig.colorbar(cmap="buda", frame=0, position="jMC+w10c/2c+h") |
| 109 | +
|
| 110 | +for code in codes: |
| 111 | + fig.text( |
| 112 | + font="10p,1,black", |
| 113 | + position=code, |
| 114 | + justify=code, |
| 115 | + text=code, |
| 116 | + offset="j0.3c/0.15c+v1p,gray30", |
| 117 | + ) |
| 118 | +fig.plot(x=x1, y=y1, style="c0.2c", fill="steelblue", no_clip=True) |
| 119 | +
|
| 120 | +fig.show(width=600) |
| 121 | +``` |
0 commit comments