Skip to content

Commit 482d14e

Browse files
authored
Figure: Defer figure activation until plotting arguments are prepared (#4756)
1 parent cf0268a commit 482d14e

32 files changed

Lines changed: 34 additions & 60 deletions

pygmt/src/basemap.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ def basemap(
140140
>>> fig.basemap(region="g", projection="H15c", frame=True)
141141
>>> fig.show()
142142
"""
143-
self._activate_figure()
144-
145143
for name, value, recommendation in (
146144
("map_scale", map_scale, "Figure.scalebar"),
147145
("compass", compass, "Figure.magnetic_rose"),
@@ -172,5 +170,6 @@ def basemap(
172170
)
173171
aliasdict.merge(kwargs)
174172

173+
self._activate_figure()
175174
with Session() as lib:
176175
lib.call_module(module="basemap", args=build_arg_list(aliasdict))

pygmt/src/choropleth.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ def choropleth(
101101
>>> fig.colorbar(frame=True)
102102
>>> fig.show()
103103
"""
104-
self._activate_figure()
105-
106104
aliasdict = AliasSystem(
107105
C=Alias(cmap, name="cmap"),
108106
I=Alias(intensity, name="intensity"),
@@ -121,6 +119,7 @@ def choropleth(
121119
# Force -G+z and -L to be set for choropleth
122120
aliasdict.update({"G": "+z", "L": True})
123121

122+
self._activate_figure()
124123
with Session() as lib:
125124
with lib.virtualfile_in(check_kind="vector", data=data) as vintbl:
126125
lib.call_module(

pygmt/src/coast.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,6 @@ def coast(
241241
>>> # Show the plot
242242
>>> fig.show()
243243
"""
244-
self._activate_figure()
245-
246244
if (
247245
kwargs.get("G", land) is None
248246
and kwargs.get("S", water) is None
@@ -295,5 +293,6 @@ def coast(
295293
)
296294
aliasdict.merge(kwargs)
297295

296+
self._activate_figure()
298297
with Session() as lib:
299298
lib.call_module(module="coast", args=build_arg_list(aliasdict))

pygmt/src/colorbar.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,6 @@ def colorbar(
480480
>>> # Show the plot
481481
>>> fig.show()
482482
"""
483-
self._activate_figure()
484-
485483
position = _parse_position(
486484
position,
487485
default=None, # Use GMT's default behavior if position is not provided.
@@ -543,5 +541,6 @@ def colorbar(
543541
)
544542
aliasdict.merge(kwargs)
545543

544+
self._activate_figure()
546545
with Session() as lib:
547546
lib.call_module(module="colorbar", args=build_arg_list(aliasdict))

pygmt/src/contour.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ def contour(
151151
$perspective
152152
$transparency
153153
"""
154-
self._activate_figure()
155-
156154
# Specify levels for contours or annotations.
157155
# One level is converted to a string with a trailing comma to separate it from
158156
# specifying an interval.
@@ -178,6 +176,7 @@ def contour(
178176
)
179177
aliasdict.merge(kwargs)
180178

179+
self._activate_figure()
181180
with Session() as lib:
182181
with lib.virtualfile_in(
183182
check_kind="vector", data=data, x=x, y=y, z=z, mincols=3

pygmt/src/directional_rose.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ def directional_rose(
8282
>>> fig.directional_rose()
8383
>>> fig.show()
8484
"""
85-
self._activate_figure()
86-
8785
# The default position is set to "TR" since GMT 6.7.0, which has no default value
8886
# in GMT 6.6.0 and earlier versions.
8987
# TODO(GMT>6.6.0): Set 'default=None' after GMT 6.7.0.
@@ -109,5 +107,6 @@ def directional_rose(
109107
t=transparency,
110108
)
111109

110+
self._activate_figure()
112111
with Session() as lib:
113112
lib.call_module(module="basemap", args=build_arg_list(aliasdict))

pygmt/src/fill_between.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ def fill_between(
113113
... )
114114
>>> fig.show()
115115
"""
116-
self._activate_figure()
117116
_x = np.atleast_1d(x)
118117
_y = np.atleast_1d(y)
119118
_y2 = np.atleast_1d(y2)
@@ -177,6 +176,7 @@ def fill_between(
177176
t=transparency,
178177
)
179178

179+
self._activate_figure()
180180
with Session() as lib:
181181
if _x2 is not None:
182182
with (

pygmt/src/grdcontour.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ def grdcontour(
156156
>>> # Show the plot
157157
>>> fig.show()
158158
"""
159-
self._activate_figure()
160-
161159
# Specify levels for the annotation and levels parameters.
162160
# One level is converted to a string with a trailing comma to separate it from
163161
# specifying an interval.
@@ -180,6 +178,7 @@ def grdcontour(
180178
)
181179
aliasdict.merge(kwargs)
182180

181+
self._activate_figure()
183182
with Session() as lib:
184183
with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd:
185184
lib.call_module(

pygmt/src/grdimage.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ def grdimage(
175175
>>> # show the plot
176176
>>> fig.show()
177177
"""
178-
self._activate_figure()
179-
180178
# Do not support -A option
181179
if any(kwargs.get(arg) is not None for arg in ["A", "img_out"]):
182180
msg = (
@@ -200,6 +198,7 @@ def grdimage(
200198
)
201199
aliasdict.merge(kwargs)
202200

201+
self._activate_figure()
203202
with Session() as lib:
204203
with (
205204
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,

pygmt/src/grdview.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,6 @@ def grdview(
291291
>>> # Show the plot
292292
>>> fig.show()
293293
"""
294-
self._activate_figure()
295-
296294
# Enable 'plane' if 'facade_fill' or 'facade_pen' are set
297295
if plane is False and (facade_fill is not None or facade_pen is not None):
298296
plane = True
@@ -339,6 +337,7 @@ def grdview(
339337
)
340338
aliasdict.merge(kwargs)
341339

340+
self._activate_figure()
342341
with Session() as lib:
343342
with (
344343
lib.virtualfile_in(check_kind="raster", data=grid) as vingrd,

0 commit comments

Comments
 (0)