Skip to content

Commit 4280487

Browse files
Merge branch 'main' into add-gallery-paragraph
2 parents c8ee6f2 + 8559120 commit 4280487

12 files changed

Lines changed: 147 additions & 143 deletions

File tree

.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@d872884a306dd4853acf0f584f4b706cf0cc72a2 # v4.13.0
87+
uses: CodSpeedHQ/action@658a901452bb54c799643e060733b7afe9121b8d # v4.14.0
8888
with:
8989
mode: "instrumentation"
9090
# 'bash -el -c' is needed to use the custom shell.

.github/workflows/ci_tests.yaml

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

156156
- name: Install uv
157-
uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57 # v8.0.0
157+
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
158158
with:
159159
activate-environment: true
160160
python-version: ${{ matrix.python-version }}

.github/workflows/dvc-diff.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ jobs:
3737

3838
- name: Setup continuous machine learning (CML)
3939
uses: iterative/setup-cml@1b5ab8766e715e8f1aab96bbb1f4f2e3e1e8af45 # v3
40+
with:
41+
vega: false
4042

4143
# Produce the markdown diff report, which should look like:
4244
# ## Summary of changed images

examples/tutorials/basics/frames.py

Lines changed: 50 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,114 +2,107 @@
22
Frames, ticks, titles, and labels
33
=================================
44
5-
Setting frame, ticks, title, etc., of the plot is handled by the ``frame``
6-
parameter that most plotting methods of the :class:`pygmt.Figure` class
7-
contain.
5+
Setting frame, ticks, titles, and labels is handled by the ``frame`` parameter that
6+
many plotting methods of the :class:`pygmt.Figure` class accept. This tutorial focuses
7+
on setting the ``frame`` parameter using the :class:`pygmt.params.Axis` and
8+
:class:`pygmt.params.Frame` classes.
89
"""
910

1011
# %%
1112
import pygmt
12-
from pygmt.params import Axis
13+
from pygmt.params import Axis, Frame
1314

1415
# %%
1516
# Plot frame
1617
# ----------
1718
#
18-
# By default, PyGMT does not add a frame to your plot. For example, we can plot
19-
# the coastlines of the world with a Mercator projection:
19+
# By default, PyGMT does not add a frame to your plot. For example, we can plot the
20+
# coastlines of the world with a Mercator projection:
2021

2122
fig = pygmt.Figure()
22-
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M25c")
23+
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M15c")
2324
fig.show()
2425

2526
# %%
26-
# To add the default GMT frame style to the plot, use ``frame="f"`` in
27-
# :meth:`pygmt.Figure.basemap` or another plotting method (which has the
28-
# ``frame`` parameter, with the exception of :meth:`pygmt.Figure.colorbar`):
27+
# To add the default GMT frame style to the plot, use ``frame=True`` in
28+
# :meth:`pygmt.Figure.basemap` or another plotting method that accepts a ``frame``
29+
# parameter:
2930

3031
fig = pygmt.Figure()
31-
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M25c")
32-
fig.basemap(frame="f")
32+
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M15c")
33+
fig.basemap(frame=True)
3334
fig.show()
3435

3536

3637
# %%
37-
# Ticks and grid lines
38-
# --------------------
38+
# Annotations, tick marks and grid lines
39+
# --------------------------------------
3940
#
40-
# The automatic frame (``frame=True`` or ``frame="af"``) adds the default GMT
41-
# frame style and automatically determines tick labels from the plot region.
42-
# In GMT the tick labels are called **a**\ nnotations.
43-
44-
fig = pygmt.Figure()
45-
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M25c")
46-
fig.basemap(frame="af")
47-
fig.show()
48-
49-
# %%
50-
# Add automatic grid lines to the plot by passing ``g`` through the ``frame``
51-
# parameter:
41+
# The default frame style includes tick labels (called annotations in GMT) and tick
42+
# marks at intervals determined by GMT, but doesn't include grid lines. To control
43+
# the presence and intervals of annotations, tick marks, and grid lines, you can use the
44+
# :class:`pygmt.params.Axis` class. The ``annot``, ``tick``, and ``grid`` attributes of
45+
# :class:`pygmt.params.Axis` control the presence and intervals of annotations, tick
46+
# marks, and grid lines, respectively. Setting them to ``True`` adds them at intervals
47+
# determined by GMT:
5248

5349
fig = pygmt.Figure()
54-
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M25c")
55-
fig.basemap(frame=Axis(annot=True, grid=True))
50+
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M15c")
51+
fig.basemap(frame=Axis(annot=True, tick=True, grid=True))
5652
fig.show()
5753

5854
# %%
59-
# To adjust the step widths of annotations, frame, and grid lines we can
60-
# add the desired step widths after ``a``, ``f``, or ``g``. In the example
61-
# below, the step widths are set to 30°, 7.5°, and 15°, respectively.
55+
# To set specific intervals, pass values to ``annot``, ``tick``, and ``grid``. In the
56+
# example below, the annotation, tick, and gridline intervals are set to 30, 7.5, and
57+
# 15 degrees, respectively.
6258

6359
fig = pygmt.Figure()
64-
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M25c")
65-
fig.basemap(frame="a30f7.5g15")
60+
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M15c")
61+
fig.basemap(frame=Axis(annot=30, tick=7.5, grid=15))
6662
fig.show()
6763

68-
6964
# %%
7065
# Title
7166
# -----
7267
#
73-
# The figure title can be set by passing **+t**\ *title* to the ``frame``
74-
# parameter of :meth:`pygmt.Figure.basemap`. Passing multiple arguments to
75-
# ``frame`` can be done by using a list, as shown in the example below.
68+
# The :class:`pygmt.params.Frame` class lets us configure frame-wide settings such as
69+
# titles. Combine it with an :class:`Axis` object to keep automatic annotations.
7670

7771
fig = pygmt.Figure()
7872
# region="TT" specifies Trinidad and Tobago using the ISO country code
79-
fig.coast(shorelines="1/0.5p", region="TT", projection="M25c")
80-
fig.basemap(frame=["a", "+tTrinidad and Tobago"])
73+
fig.coast(shorelines="1/0.5p", region="TT", projection="M15c")
74+
fig.basemap(frame=Frame(title="Trinidad and Tobago", axis=Axis(annot=True)))
8175
fig.show()
8276

8377

8478
# %%
8579
# Axis labels
8680
# -----------
8781
#
88-
# Axis labels, in GMT simply called labels, can be set by passing
89-
# **x+l**\ *label* (or starting with **y** if
90-
# labeling the y-axis) to the ``frame`` parameter of
91-
# :meth:`pygmt.Figure.basemap`. The map boundaries (or plot axes) are named as
92-
# West/west/left (**W**, **w**, **l**), South/south/bottom
93-
# (**S**, **s**, **b**), North/north/top (**N**, **n**, **t**), and
94-
# East/east/right (**E**, **e**, **r**) sides of a figure. If an uppercase
95-
# letter (**W**, **S**, **N**, **E**) is passed, the axis is plotted with
96-
# tick marks and annotations. The lowercase version
97-
# (**w**, **s**, **n**, **e**) plots the axis only with tick marks.
98-
# To only plot the axis pass **l**, **b**, **t**, **r**. By default
99-
# (``frame=True`` or ``frame="af"``), the West and the South axes are
100-
# plotted with both tick marks and annotations.
82+
# Axis labels, in GMT simply called labels, can be set through the ``xaxis`` and
83+
# ``yaxis`` parameters of :class:`Frame`. The map boundaries (or plot axes) are named as
84+
# West/west/left (**W**, **w**, **l**), South/south/bottom (**S**, **s**, **b**),
85+
# North/north/top (**N**, **n**, **t**), and East/east/right (**E**, **e**, **r**) sides
86+
# of a figure. Uppercase letters (**W**, **S**, **N**, **E**) draw axes with annotations
87+
# and tick marks, lowercase letters (**w**, **s**, **n**, **e**) draw axes with tick
88+
# marks only, and **l**, **b**, **t**, **r** draw plain axis lines without ticks or
89+
# annotations. A frame like ``Frame(axes="WS")`` draws annotated west and south axes
90+
# only.
10191
#
102-
# The example below uses a Cartesian projection, as GMT does not allow
103-
# labels to be set for geographic maps.
92+
# The example below uses a Cartesian projection, as GMT does not allow labels to be set
93+
# for geographic maps.
10494

10595
fig = pygmt.Figure()
10696
fig.basemap(
10797
region=[0, 10, 0, 20],
10898
projection="X10c/8c",
109-
# Plot axis with tick marks, annotations, and labels on the
110-
# West and South axes
99+
# Plot axis with tick marks, annotations, and labels on the West and South axes.
111100
# Plot axis with tick marks on the north and east axes
112-
frame=["WSne", "xaf+lx-axis", "yaf+ly-axis"],
101+
frame=Frame(
102+
axes="WSne",
103+
xaxis=Axis(annot=True, tick=True, label="x-axis"),
104+
yaxis=Axis(annot=True, tick=True, label="y-axis"),
105+
),
113106
)
114107
fig.show()
115108

pygmt/figure.py

Lines changed: 69 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,40 @@
99
from typing import Literal, overload
1010

1111
from pygmt._typing import PathLike
12+
from pygmt.src.basemap import basemap as _basemap
13+
from pygmt.src.choropleth import choropleth as _choropleth
14+
from pygmt.src.coast import coast as _coast
15+
from pygmt.src.colorbar import colorbar as _colorbar
16+
from pygmt.src.contour import contour as _contour
17+
from pygmt.src.directional_rose import directional_rose as _directional_rose
18+
from pygmt.src.grdcontour import grdcontour as _grdcontour
19+
from pygmt.src.grdimage import grdimage as _grdimage
20+
from pygmt.src.grdview import grdview as _grdview
21+
from pygmt.src.histogram import histogram as _histogram
22+
from pygmt.src.hlines import hlines as _hlines
23+
from pygmt.src.image import image as _image
24+
from pygmt.src.inset import inset as _inset
25+
from pygmt.src.legend import legend as _legend
26+
from pygmt.src.logo import logo as _logo
27+
from pygmt.src.magnetic_rose import magnetic_rose as _magnetic_rose
28+
from pygmt.src.meca import meca as _meca
29+
from pygmt.src.paragraph import paragraph as _paragraph
30+
from pygmt.src.plot import plot as _plot
31+
from pygmt.src.plot3d import plot3d as _plot3d
32+
from pygmt.src.psconvert import psconvert as _psconvert
33+
from pygmt.src.rose import rose as _rose
34+
from pygmt.src.scalebar import scalebar as _scalebar
35+
from pygmt.src.shift_origin import shift_origin as _shift_origin
36+
from pygmt.src.solar import solar as _solar
37+
from pygmt.src.subplot import set_panel as _set_panel
38+
from pygmt.src.subplot import subplot as _subplot
39+
from pygmt.src.ternary import ternary as _ternary
40+
from pygmt.src.text import text as _text
41+
from pygmt.src.tilemap import tilemap as _tilemap
42+
from pygmt.src.timestamp import timestamp as _timestamp
43+
from pygmt.src.velo import velo as _velo
44+
from pygmt.src.vlines import vlines as _vlines
45+
from pygmt.src.wiggle import wiggle as _wiggle
1246

1347
try:
1448
import IPython
@@ -408,42 +442,41 @@ def _repr_html_(self) -> str:
408442
html = '<img src="data:image/png;base64,{image}" width="{width}px">'
409443
return html.format(image=base64_png.decode("utf-8"), width=500)
410444

411-
from pygmt.src import ( # type: ignore[misc] # noqa: PLC0415
412-
basemap,
413-
choropleth,
414-
coast,
415-
colorbar,
416-
contour,
417-
directional_rose,
418-
grdcontour,
419-
grdimage,
420-
grdview,
421-
histogram,
422-
hlines,
423-
image,
424-
inset,
425-
legend,
426-
logo,
427-
magnetic_rose,
428-
meca,
429-
paragraph,
430-
plot,
431-
plot3d,
432-
psconvert,
433-
rose,
434-
scalebar,
435-
set_panel,
436-
shift_origin,
437-
solar,
438-
subplot,
439-
ternary,
440-
text,
441-
tilemap,
442-
timestamp,
443-
velo,
444-
vlines,
445-
wiggle,
446-
)
445+
# Attach plotting functions implemented in pygmt/src as Figure methods.
446+
basemap = _basemap
447+
choropleth = _choropleth
448+
coast = _coast
449+
colorbar = _colorbar
450+
contour = _contour
451+
directional_rose = _directional_rose
452+
grdcontour = _grdcontour
453+
grdimage = _grdimage
454+
grdview = _grdview
455+
histogram = _histogram
456+
hlines = _hlines
457+
image = _image
458+
inset = _inset
459+
legend = _legend
460+
logo = _logo
461+
magnetic_rose = _magnetic_rose
462+
meca = _meca
463+
paragraph = _paragraph
464+
plot = _plot
465+
plot3d = _plot3d
466+
psconvert = _psconvert
467+
rose = _rose
468+
scalebar = _scalebar
469+
set_panel = _set_panel
470+
shift_origin = _shift_origin
471+
solar = _solar
472+
subplot = _subplot
473+
ternary = _ternary
474+
text = _text
475+
tilemap = _tilemap
476+
timestamp = _timestamp
477+
velo = _velo
478+
vlines = _vlines
479+
wiggle = _wiggle
447480

448481

449482
def set_display(method: Literal["external", "notebook", "none", None] = None) -> None:

pygmt/helpers/decorators.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,15 @@
9191
matching. This does not apply to headers or segment headers.""",
9292
"frame": r"""
9393
frame
94-
Set frame and axes attributes for the plot. It can be a bool, a string, or
95-
a list of strings. If ``frame=True``, frame will be drawn with the default
96-
attributes. If ``frame="none"``, no frame will be drawn. A tutorial is
97-
available at :doc:`frame and axes attributes </tutorials/basics/frames>`.
98-
Full documentation is at :gmt-docs:`gmt.html#b-full`.""",
94+
Set frame and axes attributes for the plot. It can be a bool, ``"none"``,
95+
a :class:`pygmt.params.Frame` or :class:`pygmt.params.Axis` object. Raw GMT
96+
strings or sequences of strings are also supported for backward
97+
compatibility. If ``frame=True``, the frame will be drawn with the default
98+
attributes. If ``frame="none"``, no frame will be drawn. Use a
99+
:class:`pygmt.params.Frame` or :class:`pygmt.params.Axis` object for more
100+
control over the attributes of the frame and axes. A tutorial is available at
101+
:doc:`frame and axes attributes </tutorials/basics/frames>`. Full
102+
documentation is at :gmt-docs:`gmt.html#b-full`.""",
99103
"gap": r"""
100104
gap : str or list
101105
**x**\|\ **y**\|\ **z**\|\ **d**\|\ **X**\|\ **Y**\|\

0 commit comments

Comments
 (0)