Skip to content

WIP: DOC: Add Technical Reference page for justification codes #4028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 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
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
```
117 changes: 117 additions & 0 deletions doc/techref/justification_codes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
file_format: mystnb
---

# Justification codes

To adjust the position of plot embellishments, such as scalebars, directional roses,
colorbars, legends, text, and images, users can pass a two-character (order-independent)
code. Choose from

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

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)
```
Loading