Skip to content

Add the Frame/Axis class for setting frame and axes [Part 1]#4406

Open
seisman wants to merge 18 commits intomainfrom
class/frame-part1
Open

Add the Frame/Axis class for setting frame and axes [Part 1]#4406
seisman wants to merge 18 commits intomainfrom
class/frame-part1

Conversation

@seisman
Copy link
Member

@seisman seisman commented Feb 10, 2026

This PR implements the Frame/Axis class for setting frame and axes attributes. It's a subset of PR #4016 because the -B option is complicated, and it will take a long time to finish #4016, which again will delay the paper submission.

Currently, only a small subset of the -B option is implemented in this PR, but it should already cover most use cases.

Here is a comparison table between the GMT CLI and the PyGMT versions:

GMT PyGMT
-B frame=True
-BWSEN frame=Frame("WSEN") or frame=Frame(axes="WSEN")
-BWSEN+tMY TITLE frame=Frame("WSEN", title="MY TITLE")
-Ba frame=Axis(annnot=True)
-Bafg frame=Axis(annot=True, tick=True, grid=True)
-Ba30f15g5 frame=Axis(annot=30, tick=15, grid=5)
-Ba30f15g5+lLABEL frame=Axis(annot=30, tick=15, grid=5, label="LABEL")
-BWSEN+tTITLE -Bxa30f15g5+lXlabel -Bya4f2g1+lYlabel frame=Frame("WSEN", title="TITLE", xaxis=Axis(annot=30, tick=15, grid=5, label="Ylabel"), yaxis=Axis(annot=4, tick=4, grid=1, label="Ylabel"))

This PR doens't break backward-compatibility, so frame="WSEN", frame="afg", frame="a30f15g5", frame=["WSEN+tTITLE", "xafg", "yafg"] are still supported.

Preview:

@seisman seisman added enhancement Improving an existing feature feature Brand new feature and removed enhancement Improving an existing feature labels Feb 10, 2026
@seisman seisman added this to the 0.19.0 milestone Feb 10, 2026
@seisman seisman added the needs review This PR has higher priority and needs review. label Feb 10, 2026
@seisman seisman requested a review from a team February 25, 2026 05:06
@seisman seisman removed the needs review This PR has higher priority and needs review. label Mar 6, 2026
@seisman seisman added the final review call This PR requires final review and approval from a second reviewer label Mar 6, 2026
>>> fig.basemap(
... region=[0, 10, 0, 20],
... projection="X10c/10c",
... frame=Axis(annot=4, tick=2, grid=1),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "long" version would be
frame=Frame(axis=Axis(annot=4, tick=2, grid=1))
?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and focused start, just some comments for now.

>>> fig.show()
"""

#: Specify the interval for annoations. It can be ``True`` to let GMT decide the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#: Specify the interval for annoations. It can be ``True`` to let GMT decide the
#: Specify the interval for annotations. It can be ``True`` to let GMT decide the

Comment on lines +35 to +40
#: interval automatically; or a value to set a specific interval in the format of
#: *stride*\ [±\ *phase*][*unit*], where, *stride* is the interval, *phase* is the
#: offset to shift the annotations by that amount, and *unit* is one of the
#: :gmt-docs:`18 supported unit codes <reference/options.html#tbl-units>` related to
#: time intervals.
annot: float | bool = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow str type also considering phase/unit can be appended (e.g. in the case of time axes)?

Suggested change
#: interval automatically; or a value to set a specific interval in the format of
#: *stride*\ [±\ *phase*][*unit*], where, *stride* is the interval, *phase* is the
#: offset to shift the annotations by that amount, and *unit* is one of the
#: :gmt-docs:`18 supported unit codes <reference/options.html#tbl-units>` related to
#: time intervals.
annot: float | bool = False
#: interval automatically; or a value to set a specific interval in the format of
#: *stride*\ [±\ *phase*][*unit*], where, *stride* is the interval, *phase* is the
#: offset to shift the annotations by that amount, and *unit* is one of the
#: :gmt-docs:`18 supported unit codes <reference/options.html#tbl-units>` related to
#: time intervals.
annot: float | str | bool = False

Comment on lines +42 to +46
#: Specify the interval for ticks. Same format as ``annot``.
tick: float | bool = False

#: Specify the interval for gridlines. Same format as ``annot``.
grid: float | bool = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#: Specify the interval for ticks. Same format as ``annot``.
tick: float | bool = False
#: Specify the interval for gridlines. Same format as ``annot``.
grid: float | bool = False
#: Specify the interval for ticks. Same format as ``annot``.
tick: float | str | bool = False
#: Specify the interval for gridlines. Same format as ``annot``.
grid: float | str | bool = False

Alias(self.annot, name="annot", prefix="a"),
Alias(self.tick, name="tick", prefix="f"),
Alias(self.grid, name="grid", prefix="g"),
Alias(self.label, name="label", prefix="+l"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to alias +L "forces a horizontal label for y-axes, which is useful for very short labels" (https://docs.generic-mapping-tools.org/6.6/gmt.html#axes-settings) later?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Brand new feature final review call This PR requires final review and approval from a second reviewer high-priority

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants