Skip to content
Merged
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
176fcab
Add first ideas for Technical Reference page for justification codes
yvonnefroehlich Jul 29, 2025
34d4409
Remove execution permission
yvonnefroehlich Jul 29, 2025
9e493a2
Update
yvonnefroehlich Jul 29, 2025
2a222cf
Focus on two-letter codes
yvonnefroehlich Jul 30, 2025
e591ac2
Adjust docs
yvonnefroehlich Jul 30, 2025
9e86f47
Merge branch 'main' into add-techref-justify
yvonnefroehlich Jul 30, 2025
80c3400
Add code for sektch to explain justification codes
yvonnefroehlich Aug 1, 2025
f8487d1
Merge remote-tracking branch 'origin/add-techref-justify' into add-te…
yvonnefroehlich Aug 1, 2025
e8e2441
Split script
yvonnefroehlich Aug 1, 2025
83ba9e4
Merge branch 'main' into add-techref-justify
yvonnefroehlich Aug 1, 2025
14234fc
Add sketch for reference and anchor point
yvonnefroehlich Aug 1, 2025
b119946
Adjust cmap for better contrast
yvonnefroehlich Aug 1, 2025
06fadae
Adjust cmap for better contrast
yvonnefroehlich Aug 1, 2025
5bd36a3
Adjust font size
yvonnefroehlich Aug 1, 2025
839054b
No equal offsets in x and y directions
yvonnefroehlich Aug 1, 2025
4267fe3
Use consistent order in justification codes
yvonnefroehlich Aug 1, 2025
cad5a02
Merge branch 'main' into add-techref-justify
yvonnefroehlich Aug 2, 2025
b59e858
Improve docs
yvonnefroehlich Aug 2, 2025
29e07bd
Try defining variables ones
yvonnefroehlich Aug 2, 2025
0303e69
Add docs
yvonnefroehlich Aug 4, 2025
e1656bb
Move content for reference and anchor point to seperate file
yvonnefroehlich Aug 4, 2025
c5cf5a8
Update index
yvonnefroehlich Aug 4, 2025
b7076a7
Add import and variable definitions
yvonnefroehlich Aug 4, 2025
6bc3389
Use Unix LF
yvonnefroehlich Aug 6, 2025
0ce44f8
Remove execution permission
yvonnefroehlich Aug 6, 2025
6ea139d
Merge branch 'main' into add-techref-justify
yvonnefroehlich Aug 9, 2025
573ebd2
Merge remote-tracking branch 'origin' into add-techref-justify
yvonnefroehlich Aug 9, 2025
9534828
Merge remote-tracking branch 'origin/add-techref-justify' into add-te…
yvonnefroehlich Aug 9, 2025
e29f5e6
Merge branch 'main' into add-techref-justify
yvonnefroehlich Aug 10, 2025
47dc728
Merge remote-tracking branch 'origin/add-techref-justify' into add-te…
yvonnefroehlich Aug 10, 2025
786b014
Adjust colormap
yvonnefroehlich Aug 10, 2025
2ef345c
Merge branch 'main' into add-techref-justify
yvonnefroehlich Aug 10, 2025
873a1ba
Remove reference anchor points content
yvonnefroehlich Aug 10, 2025
952624d
Merge branch 'main' into add-techref-justify
yvonnefroehlich Aug 11, 2025
4233f32
Remove unneeded variables
yvonnefroehlich Aug 13, 2025
d827aec
Adjust docs
yvonnefroehlich Aug 13, 2025
06f3347
Merge branch 'main' into add-techref-justify
yvonnefroehlich Aug 14, 2025
b63f97f
Merge branch 'main' into add-techref-justify
yvonnefroehlich Aug 18, 2025
efcaa71
Merge branch 'main' into add-techref-justify
yvonnefroehlich Aug 19, 2025
1c45456
Merge branch 'main' into add-techref-justify
yvonnefroehlich Aug 20, 2025
04f7fcc
TEST: list for alias needs at least two enteries
yvonnefroehlich Aug 20, 2025
a39d10d
TEST: Revert
yvonnefroehlich Aug 20, 2025
c1b9227
TEST: Copy list from coast method
yvonnefroehlich Aug 20, 2025
cdafedd
Merge branch 'main' into add-techref-justify
yvonnefroehlich Aug 20, 2025
8fe356d
Merge branch 'main' into add-techref-justify
yvonnefroehlich Aug 20, 2025
c00369b
Improve docs
yvonnefroehlich Aug 22, 2025
fe324a4
Update formulation
yvonnefroehlich Aug 22, 2025
7027cd0
Merge branch 'main' into add-techref-justify
yvonnefroehlich Aug 22, 2025
16e7a40
TEST: remove gallery example linestrings
yvonnefroehlich Aug 22, 2025
4f72189
Revert "TEST: remove gallery example linestrings"
yvonnefroehlich Aug 22, 2025
145eb1b
Merge branch 'main' into add-techref-justify
yvonnefroehlich Aug 23, 2025
9c6275b
Merge branch 'main' into add-techref-justify
yvonnefroehlich Aug 23, 2025
2e22067
Merge branch 'main' into add-techref-justify
yvonnefroehlich Aug 25, 2025
239036f
Link to techref in docs
yvonnefroehlich Aug 25, 2025
38d8c85
Fix indent
yvonnefroehlich Aug 25, 2025
e8b8fd7
Mention techref in gallery examples and tutorials
yvonnefroehlich Aug 25, 2025
0243529
Remove blank line
yvonnefroehlich Aug 25, 2025
3dbcacc
Mention techref in docs
yvonnefroehlich Aug 25, 2025
4322793
Merge branch 'main' into add-techref-justify
yvonnefroehlich Aug 26, 2025
1f0318c
Merge branch 'main' into add-techref-justify
yvonnefroehlich Sep 1, 2025
6fbefa3
Improve formulation
yvonnefroehlich Sep 2, 2025
6e79fcb
Add justification code example
yvonnefroehlich Sep 2, 2025
0f1120e
Highlight points in bold
yvonnefroehlich Sep 2, 2025
d37f3dc
Improve formulation
yvonnefroehlich Sep 2, 2025
10d94ea
No need to escape
yvonnefroehlich Sep 2, 2025
a06ad41
Add blank line
yvonnefroehlich Sep 2, 2025
b6cab8c
Add blank line
yvonnefroehlich Sep 2, 2025
e8d0602
Use line length
yvonnefroehlich Sep 2, 2025
dd648cf
Add blank line
yvonnefroehlich Sep 2, 2025
a930970
Add more information
yvonnefroehlich Sep 2, 2025
10cd6f3
Remove one blank line
yvonnefroehlich Sep 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/techref/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ fonts.md
text_formatting.md
patterns.md
encodings.md
justification_codes.md
environment_variables.md
```
120 changes: 120 additions & 0 deletions doc/techref/justification_codes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
---
file_format: mystnb
---

# Justification codes

To place plot embellishments, such as scalebars, directional roses, colorbars,
legends, text, or images on a figure, two points have to be specified: a point
somewhere on the figure (**reference point**) and a point on the feature (**anchor
point**). For both, users can use a two-character code, a combination of a vertical
code and a horizontal code (order-independent):

- Vertical: **T**(op), **M**(iddle), **B**(ottom)
- Horizontal: **L**(eft), **C**(entre), **R**(ight)

For example, `"TL"` means **T**op **L**eft.
The possible nine justification codes are visualized in the sketch below:

```{code-cell}
---
tags: [remove-input]
---
"""
Script showing the justification codes used in GMT / PyGMT.
"""
import pygmt

size = 5
x1 = [-size, 0, size, size, size, 0, -size, -size, 0]
y1 = [-size, -size, -size, 0, size, size, size, 0, 0]
codes = ["BL", "BC", "BR", "MR", "TR", "TC", "TL", "ML", "MC"]

fig = pygmt.Figure()
fig.basemap(projection="X10c/6c", region=[-size, size, -size, size], frame=0)

fig.text(
font="15p,1,black",
x=x1,
y=y1,
text=codes,
justify=codes,
offset="j0.5c/0.5c+v2p,gray30",
)

fig.plot(x=x1, y=y1, style="c0.3c", fill="steelblue", no_clip=True)

fig.text(
font="15p",
offset="j0.5c/0.5c",
no_clip=True,
x=[size, size, size, -size, 0, size],
y=[size, 0, -size, size, size, size],
justify=["ML", "ML", "ML", "BC", "BC", "BC"],
text=[
"@%1%T@%%op",
"@%1%M@%%iddle",
"@%1%B@%%ottom",
"@%1%L@%%eft",
"@%1%C@%%enter",
"@%1%R@%%ight",
],
)

fig.show(width=600)
```

For a non-rectangular geographic basemap, the justification codes refer to the map
bounding box:

```{code-cell}
---
tags: [remove-input]
---
"""
Script showing justification codes for non-rectangular geographic basemaps.
"""
fig = pygmt.Figure()
fig.basemap(projection="H10c", region="g", frame=0)

for code in codes:
fig.text(
font="10p,1,black",
position=code,
justify=code,
text=code,
offset="j0.5c/0.5c+v2p,gray30",
)
fig.text(font="10p,steelblue", position=code, justify="MC", text="●", no_clip=True)

fig.show(width=600)
```


Plot embellishments can be abstracted as rectangles. Here, the justification codes are
shown exemplary for a colorbar.

```{code-cell}
---
tags: [remove-input]
---
"""
Script showing justification codes for plot embellishments, e.g., a colorbar.
"""
fig = pygmt.Figure()
fig.basemap(projection="X10c/2c", region=[-size, size, -size, size], frame=0)

fig.colorbar(cmap="buda", frame=0, position="jMC+w10c/2c+h")

for code in codes:
fig.text(
font="10p,1,black",
position=code,
justify=code,
text=code,
offset="j0.3c/0.15c+v1p,gray30",
)
fig.plot(x=x1, y=y1, style="c0.2c", fill="steelblue", no_clip=True)

fig.show(width=600)
```
5 changes: 2 additions & 3 deletions examples/gallery/embellishments/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
followed by the desired interval. The placement of the colorbar is set
via the ``position`` parameter. There are the following options:

- **j/J**: placed inside/outside the plot bounding box using any 2-character
combination of vertical (**T**\ op, **M**\ iddle, **B**\ ottom) and
horizontal (**L**\ eft, **C**\ enter, **R**\ ight) alignment codes, e.g.
- **j/J**: placed inside/outside the plot bounding box using a
:doc:`2-character justification code </techref/justification_codes>`, e.g.,
``position="jTR"`` for Top Right.
- **g**: using map coordinates, e.g. ``position="g170/-45"`` for longitude
170° East, latitude 45° South.
Expand Down
14 changes: 6 additions & 8 deletions examples/gallery/embellishments/scalebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
of the reference point. Choose from

- **g**: Give map coordinates as *longitude*\/\ *latitude*.
- **j**\|\ **J**: Specify a two-character (order independent) code.
Choose from vertical **T**\(op), **M**\(iddle), or **B**\(ottom) and
horizontal **L**\(eft), **C**\(entre), or **R**\(ight). Lower /
uppercase **j** / **J** mean inside / outside of the map bounding
box.
- **j**\|\ **J**: Specify a
:doc:`2-character justification code </techref/justification_codes>`.
Lower / uppercase **j** / **J** mean inside / outside of the map
bounding box.
- **n**: Give normalized bounding box coordinates as *nx*\/\ *ny*.
- **x**: Give plot coordinates as *x*\/\ *y*.

Expand All @@ -26,9 +25,8 @@
**+c** is appended the middle of the map is used. Note that *slon* is only
optional for projections with constant scale along parallels, e.g.,
Mercator projection.
- justify: **+j**. Set the anchor point. Specify a two-character (order
independent) code. Choose from vertical **T**\(op), **M**\(iddle), or
**B**\(ottom) and horizontal **L**\(eft), **C**\(entre), or **R**\(ight).
- justify: **+j**. Set the anchor point. Specify a
:doc:`2-character justification code </techref/justification_codes>`.
- offset: **+o**\ *offset* or **+o**\ *xoffset*/\ *yoffset*. Give either a
common shift or individual shifts in x- (longitude) and y- (latitude)
directions.
Expand Down
14 changes: 3 additions & 11 deletions examples/tutorials/basics/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@
# * ``angle``: Specifies the rotation of the text. It is measured counter-clockwise
# from the horizontal in degrees.
# * ``justify``: Defines the anchor point of the bounding box for the text. It is
# specified by a two-letter (order independent) code, chosen from:
#
# * Vertical: **T**\(op), **M**\(iddle), **B**\(ottom)
# * Horizontal: **L**\(eft), **C**\(entre), **R**\(ight)
#
# specified by a :doc:`2-character justification code </techref/justification_codes>`.
# * ``offset``: Shifts the text relatively to the reference point.

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

Expand Down
10 changes: 6 additions & 4 deletions pygmt/src/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ def colorbar(
[**+n**\ [*txt*]][**+o**\ *dx*\ [/*dy*]].
Define the reference point on the map for the color scale using one of
four coordinate systems: (1) Use **g** for map (user) coordinates, (2)
use **j** or **J** for setting *refpoint* via a 2-character
justification code that refers to the (invisible) map domain rectangle,
use **j** or **J** for setting *refpoint* via a
:doc:`2-character justification code </techref/justification_codes>`
that refers to the (invisible) map domain rectangle,
(3) use **n** for normalized (0-1) coordinates, or (4) use **x** for
plot coordinates (inches, cm, etc.). All but **x** requires both
``region`` and ``projection`` to be specified. Append **+w** followed
Expand All @@ -78,8 +79,9 @@ def colorbar(
reverse the scale bar. Append **+h** to get a horizontal scale
[Default is vertical (**+v**)]. By default, the anchor point on the
scale is assumed to be the bottom left corner (**BL**), but this can
be changed by appending **+j** followed by a 2-character
justification code *justify*.
be changed by appending **+j** followed by a
:doc:`2-character justification code </techref/justification_codes>`
*justify*.
box : bool or str
[**+c**\ *clearances*][**+g**\ *fill*][**+i**\ [[*gap*/]\ *pen*]]\
[**+p**\ [*pen*]][**+r**\ [*radius*]][**+s**\ [[*dx*/*dy*/][*shade*]]].
Expand Down
8 changes: 5 additions & 3 deletions pygmt/src/inset.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def inset(

Append **g**\ *lon*/*lat* for map (user) coordinates,
**j**\ *code* or **J**\ *code* for setting the *refpoint* via a
2-character justification code that refers to the (invisible)
:doc:`2-character justification code </techref/justification_codes>`
that refers to the (invisible)
projected map bounding box, **n**\ *xn*/*yn* for normalized (0-1)
bounding box coordinates, or **x**\ *x*/*y* for plot
coordinates (inches, centimeters, points, append unit).
Expand All @@ -75,8 +76,9 @@ def inset(
Append **+w**\ *width*\ [/*height*] of bounding rectangle or box
in plot coordinates (inches, centimeters, etc.). By default, the
anchor point on the scale is assumed to be the bottom left corner
(**BL**), but this can be changed by appending **+j** followed by
a 2-character justification code *justify*.
(**BL**), but this can be changed by appending **+j** followed by a
:doc:`2-character justification code </techref/justification_codes>`
*justify*.
**Note**: If **j** is used then *justify* defaults to the same
as *refpoint*, if **J** is used then *justify* defaults to the
mirror opposite of *refpoint*. Specify inset box attributes via
Expand Down
18 changes: 7 additions & 11 deletions pygmt/src/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915
* *y*: Y coordinate or latitude
* *angle*: Angle in degrees counter-clockwise from horizontal
* *font*: Text size, font, and color
* *justify*: Two-character justification code
* *justify*:
:doc:`2-character justification code </techref/justification_codes>`
* *text*: The text string to typeset

The *angle*, *font*, and *justify* columns are optional and can be set
Expand All @@ -104,12 +105,8 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915
position
Set reference point on the map for the text by using x, y
coordinates extracted from ``region`` instead of providing them
through ``x``/``y``. Specify with a two-letter (order independent)
code, chosen from:

* Vertical: **T**\ (op), **M**\ (iddle), **B**\ (ottom)
* Horizontal: **L**\ (eft), **C**\ (entre), **R**\ (ight)

through ``x``/``y``. Specify with a
:doc:`2-character justification code </techref/justification_codes>`.
For example, ``position="TL"`` plots the text at the Top Left corner
of the map.
text
Expand All @@ -129,10 +126,9 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915
columns.
justify
Set the alignment which refers to the part of the text string that
will be mapped onto the (x, y) point. Choose a two-letter
combination of **L**, **C**, **R** (for left, center, or right) and
**T**, **M**, **B** (for top, middle, or bottom). E.g., **BL** for
bottom left. If no justification is explicitly given
will be mapped onto the (x, y) point. Choose a
:doc:`2-character justification code </techref/justification_codes>`,
e.g., **BL** for Bottom Left. If no justification is explicitly given
(i.e. ``justify=True``), then the input to ``textfiles`` must have
this as a column.
{projection}
Expand Down
Loading