Skip to content

Commit 9a4f259

Browse files
committed
Merge branch 'main' into feature/direction_rose
2 parents cee6028 + a9630ce commit 9a4f259

File tree

13 files changed

+156
-45
lines changed

13 files changed

+156
-45
lines changed

.github/workflows/benchmarks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484

8585
# Run the benchmark tests
8686
- name: Run benchmarks
87-
uses: CodSpeedHQ/action@0b6e7a3d96c9d2a6057e7bcea6b45aaf2f7ce60b # v3.8.0
87+
uses: CodSpeedHQ/action@76578c2a7ddd928664caa737f0e962e3085d4e7c # v3.8.1
8888
with:
8989
# 'bash -el -c' is needed to use the custom shell.
9090
# See https://github.com/CodSpeedHQ/action/issues/65.

.github/workflows/ci_tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ jobs:
151151
GH_TOKEN: ${{ github.token }}
152152

153153
- name: Install uv
154-
uses: astral-sh/setup-uv@d9e0f98d3fc6adb07d1e3d37f3043649ddad06a1 # v6.5.0
154+
uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v6.6.0
155155
with:
156156
activate-environment: true
157157
python-version: ${{ matrix.python-version }}

.github/workflows/dvc-diff.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
persist-credentials: false
3131

3232
- name: Setup data version control (DVC)
33-
uses: iterative/setup-dvc@2508d098217d24eef3c0e8d7bc0ce7b9ca0723c3 # v1.1.2
33+
uses: iterative/setup-dvc@175771be1dc3d119268e00a896b52a4b77decb5e # v1.2.0
3434

3535
- name: Setup continuous machine learning (CML)
3636
uses: iterative/setup-cml@f714cd201b7183852dd6f94192b34e7618717560 # v2.0.0

.github/workflows/format-command.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
# Generate token from GenericMappingTools bot
19-
- uses: actions/create-github-app-token@v2.0.6
19+
- uses: actions/create-github-app-token@v2.1.1
2020
id: generate-token
2121
with:
2222
app-id: ${{ secrets.APP_ID }}

.github/workflows/release-baseline-images.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
persist-credentials: false
2929

3030
- name: Setup data version control (DVC)
31-
uses: iterative/setup-dvc@2508d098217d24eef3c0e8d7bc0ce7b9ca0723c3 # v1.1.2
31+
uses: iterative/setup-dvc@175771be1dc3d119268e00a896b52a4b77decb5e # v1.2.0
3232

3333
- name: Pull baseline image data from dvc remote
3434
run: dvc pull && ls -lhR pygmt/tests/baseline/

doc/techref/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ fonts.md
1414
text_formatting.md
1515
patterns.md
1616
encodings.md
17+
justification_codes.md
1718
environment_variables.md
1819
```

doc/techref/justification_codes.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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+
```

examples/gallery/embellishments/colorbar.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
followed by the desired interval. The placement of the colorbar is set
1212
via the ``position`` parameter. There are the following options:
1313
14-
- **j/J**: placed inside/outside the plot bounding box using any 2-character
15-
combination of vertical (**T**\ op, **M**\ iddle, **B**\ ottom) and
16-
horizontal (**L**\ eft, **C**\ enter, **R**\ ight) alignment codes, e.g.
14+
- **j/J**: placed inside/outside the plot bounding box using a
15+
:doc:`2-character justification code </techref/justification_codes>`, e.g.,
1716
``position="jTR"`` for Top Right.
1817
- **g**: using map coordinates, e.g. ``position="g170/-45"`` for longitude
1918
170° East, latitude 45° South.

examples/gallery/embellishments/scalebar.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
of the reference point. Choose from
1111
1212
- **g**: Give map coordinates as *longitude*\/\ *latitude*.
13-
- **j**\|\ **J**: Specify a two-character (order independent) code.
14-
Choose from vertical **T**\(op), **M**\(iddle), or **B**\(ottom) and
15-
horizontal **L**\(eft), **C**\(entre), or **R**\(ight). Lower /
16-
uppercase **j** / **J** mean inside / outside of the map bounding
17-
box.
13+
- **j**\|\ **J**: Specify a
14+
:doc:`2-character justification code </techref/justification_codes>`.
15+
Lower / uppercase **j** / **J** mean inside / outside of the map
16+
bounding box.
1817
- **n**: Give normalized bounding box coordinates as *nx*\/\ *ny*.
1918
- **x**: Give plot coordinates as *x*\/\ *y*.
2019
@@ -26,9 +25,8 @@
2625
**+c** is appended the middle of the map is used. Note that *slon* is only
2726
optional for projections with constant scale along parallels, e.g.,
2827
Mercator projection.
29-
- justify: **+j**. Set the anchor point. Specify a two-character (order
30-
independent) code. Choose from vertical **T**\(op), **M**\(iddle), or
31-
**B**\(ottom) and horizontal **L**\(eft), **C**\(entre), or **R**\(ight).
28+
- justify: **+j**. Set the anchor point. Specify a
29+
:doc:`2-character justification code </techref/justification_codes>`.
3230
- offset: **+o**\ *offset* or **+o**\ *xoffset*/\ *yoffset*. Give either a
3331
common shift or individual shifts in x- (longitude) and y- (latitude)
3432
directions.

examples/tutorials/basics/text.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@
3737
# * ``angle``: Specifies the rotation of the text. It is measured counter-clockwise
3838
# from the horizontal in degrees.
3939
# * ``justify``: Defines the anchor point of the bounding box for the text. It is
40-
# specified by a two-letter (order independent) code, chosen from:
41-
#
42-
# * Vertical: **T**\(op), **M**\(iddle), **B**\(ottom)
43-
# * Horizontal: **L**\(eft), **C**\(entre), **R**\(ight)
44-
#
40+
# specified by a :doc:`2-character justification code </techref/justification_codes>`.
4541
# * ``offset``: Shifts the text relatively to the reference point.
4642

4743
fig = pygmt.Figure()
@@ -191,12 +187,8 @@
191187
#
192188
# Instead of using the ``x`` and ``y`` parameters, the ``position`` parameter can be
193189
# specified to set the reference point for the text on the plot. As for the ``justify``
194-
# parameter, the ``position`` parameter is specified by a two-letter (order independent)
195-
# code, chosen from:
196-
#
197-
# * Vertical: **T**\(op), **M**\(iddle), **B**\(ottom)
198-
# * Horizontal: **L**\(eft), **C**\(entre), **R**\(ight)
199-
#
190+
# parameter, the ``position`` parameter is specified by a
191+
# :doc:`2-character justification code </techref/justification_codes>`.
200192
# This can be helpful to add a tag to a subplot or text labels out of the plot or map
201193
# frame, e.g., for depth slices.
202194

0 commit comments

Comments
 (0)