Skip to content

Commit 6d3e2ef

Browse files
committed
Add alias for region and projections and improve the examples
1 parent 6ba988b commit 6d3e2ef

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

examples/tutorials/advanced/insets.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,15 @@
9797
frame="a",
9898
)
9999
# This does not include an inset fill as it is covered by the inset figure
100-
with fig.inset(position="jBL+w3c/4c+o0.5c/0.2c", box="+pblack"):
100+
# Inset width/height are determined by the region and projection parameters.
101+
with fig.inset(
102+
position="jBL+o0.5c/0.2c",
103+
box="+pblack",
104+
region=[-80, -65, 35, 50],
105+
projection="M3c",
106+
):
101107
# Use a plotting function to create a figure inside the inset.
102-
# Use '?' when specifying the projection width, to automatically
103-
# determine the map size from the inset box size.
104108
fig.coast(
105-
region=[-80, -65, 35, 50],
106-
projection="M?",
107109
land="gray",
108110
borders=[1, 2],
109111
shorelines="1/thin",

pygmt/src/inset.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@
1111

1212
@fmt_docstring
1313
@contextlib.contextmanager
14-
@use_alias(D="position", F="box", M="margin", N="no_clip", V="verbose")
15-
@kwargs_to_strings(D="sequence", M="sequence")
14+
@use_alias(
15+
D="position",
16+
F="box",
17+
J="projection",
18+
M="margin",
19+
N="no_clip",
20+
R="region",
21+
V="verbose",
22+
)
23+
@kwargs_to_strings(D="sequence", M="sequence", R="sequence")
1624
def inset(self, **kwargs):
1725
r"""
1826
Create an inset figure to be placed within a larger figure.
@@ -98,6 +106,8 @@ def inset(self, **kwargs):
98106
no_clip : bool
99107
Do NOT clip features extruding outside map inset boundaries [Default
100108
is clip].
109+
{R}
110+
{J}
101111
{V}
102112
103113
Examples
@@ -107,20 +117,22 @@ def inset(self, **kwargs):
107117
>>> # Create the larger figure
108118
>>> fig = pygmt.Figure()
109119
>>> fig.coast(region="MG+r2", water="lightblue", shorelines="thin")
110-
>>> # Use a "with" statement to initialize the inset context manager
111-
>>> # Setting the position to top left and a width of 3.5 centimeters
112-
>>> with fig.inset(position="jTL+w3.5c+o0.2c", margin=0, box="+pgreen"):
113-
... # Map elements under the "with" statement are plotted in the inset.
114-
... # Use '?' when specifying the projection width, to automatically
115-
... # determine the map size from the inset box size.
120+
>>> # Use a "with" statement to initialize the inset context manager.
121+
>>> # Seting the position to top left with an 0.2 cm offset and
122+
>>> # draw a green inset box.
123+
>>> # The inset size is determined by the region and projection parameters.
124+
>>> with fig.inset(
125+
... position="jTL+o0.2c",
126+
... margin=0,
127+
... box="+pgreen",
128+
... region="g",
129+
... projection="G47/-20/3.5c",
130+
... ):
116131
... fig.coast(
117-
... region="g",
118-
... projection="G47/-20/?",
119132
... land="gray",
120133
... water="white",
121134
... dcw="MG+gred",
122135
... )
123-
...
124136
>>> # Map elements outside the "with" block are plotted in the main figure
125137
>>> fig.logo(position="jBR+o0.2c+w3c")
126138
>>> fig.show() # doctest: +SKIP

0 commit comments

Comments
 (0)