diff --git a/pygmt/figure.py b/pygmt/figure.py index f9c8478747d..591c30b5c85 100644 --- a/pygmt/figure.py +++ b/pygmt/figure.py @@ -4,6 +4,7 @@ import base64 import os +import warnings from pathlib import Path from tempfile import TemporaryDirectory from typing import Literal, overload @@ -119,12 +120,19 @@ def _activate_figure(self) -> None: with Session() as lib: lib.call_module(module="figure", args=[self._name, fmt]) + # TODO(PyGMT>=v0.18.0): Remove the _preprocess method. def _preprocess(self, **kwargs): """ Call the ``figure`` module before each plotting command to ensure we're plotting to this particular figure. """ self._activate_figure() + warnings.warn( + "The Figure._preprocess() method is deprecated since v0.16.0 and will be " + "removed in v0.18.0. Use Figure._activate_figure() instead.", + FutureWarning, + stacklevel=2, + ) return kwargs @property diff --git a/pygmt/src/basemap.py b/pygmt/src/basemap.py index f9acc949042..b083d8143b6 100644 --- a/pygmt/src/basemap.py +++ b/pygmt/src/basemap.py @@ -82,6 +82,6 @@ def basemap(self, **kwargs): {perspective} {transparency} """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() with Session() as lib: lib.call_module(module="basemap", args=build_arg_list(kwargs)) diff --git a/pygmt/src/coast.py b/pygmt/src/coast.py index 22ecd018854..53d8db97bf4 100644 --- a/pygmt/src/coast.py +++ b/pygmt/src/coast.py @@ -193,7 +193,7 @@ def coast(self, **kwargs): >>> # Show the plot >>> fig.show() """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() if not args_in_kwargs(args=["C", "G", "S", "I", "N", "E", "Q", "W"], kwargs=kwargs): msg = ( "At least one of the following parameters must be specified: " diff --git a/pygmt/src/colorbar.py b/pygmt/src/colorbar.py index 501e24c6769..7ae261ac29a 100644 --- a/pygmt/src/colorbar.py +++ b/pygmt/src/colorbar.py @@ -144,6 +144,6 @@ def colorbar(self, **kwargs): >>> # Show the plot >>> fig.show() """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() with Session() as lib: lib.call_module(module="colorbar", args=build_arg_list(kwargs)) diff --git a/pygmt/src/contour.py b/pygmt/src/contour.py index ad20bf80c2a..b5b95a20c16 100644 --- a/pygmt/src/contour.py +++ b/pygmt/src/contour.py @@ -133,7 +133,7 @@ def contour( {perspective} {transparency} """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() # Specify levels for contours or annotations. # One level is converted to a string with a trailing comma to separate it from diff --git a/pygmt/src/grdcontour.py b/pygmt/src/grdcontour.py index 8d733ed2dd0..04862ad2ad1 100644 --- a/pygmt/src/grdcontour.py +++ b/pygmt/src/grdcontour.py @@ -138,7 +138,7 @@ def grdcontour(self, grid: PathLike | xr.DataArray, **kwargs): >>> # Show the plot >>> fig.show() """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() # Specify levels for the annotation and levels parameters. # One level is converted to a string with a trailing comma to separate it from diff --git a/pygmt/src/grdimage.py b/pygmt/src/grdimage.py index 8e2e136ae55..edfe7ad0866 100644 --- a/pygmt/src/grdimage.py +++ b/pygmt/src/grdimage.py @@ -156,7 +156,7 @@ def grdimage(self, grid: PathLike | xr.DataArray, **kwargs): >>> # show the plot >>> fig.show() """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() # Do not support -A option if any(kwargs.get(arg) is not None for arg in ["A", "img_out"]): diff --git a/pygmt/src/grdview.py b/pygmt/src/grdview.py index 23141e79ea9..8459b4beeb3 100644 --- a/pygmt/src/grdview.py +++ b/pygmt/src/grdview.py @@ -140,7 +140,7 @@ def grdview(self, grid: PathLike | xr.DataArray, **kwargs): >>> # Show the plot >>> fig.show() """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() with Session() as lib: with ( lib.virtualfile_in(check_kind="raster", data=grid) as vingrd, diff --git a/pygmt/src/histogram.py b/pygmt/src/histogram.py index d721e3778a5..a74c5f04693 100644 --- a/pygmt/src/histogram.py +++ b/pygmt/src/histogram.py @@ -135,7 +135,7 @@ def histogram(self, data: PathLike | TableLike, **kwargs): {transparency} {wrap} """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() with Session() as lib: with lib.virtualfile_in(check_kind="vector", data=data) as vintbl: lib.call_module( diff --git a/pygmt/src/hlines.py b/pygmt/src/hlines.py index e2c390b4eea..7ee5bb3b5cc 100644 --- a/pygmt/src/hlines.py +++ b/pygmt/src/hlines.py @@ -80,7 +80,7 @@ def hlines( >>> fig.legend() >>> fig.show() """ - self._preprocess() + self._activate_figure() # Determine the x limits from the current plot region if not specified. if xmin is None or xmax is None: diff --git a/pygmt/src/image.py b/pygmt/src/image.py index a915db5f97f..84c1923e54f 100644 --- a/pygmt/src/image.py +++ b/pygmt/src/image.py @@ -68,6 +68,6 @@ def image(self, imagefile: PathLike, **kwargs): {perspective} {transparency} """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() with Session() as lib: lib.call_module(module="image", args=build_arg_list(kwargs, infile=imagefile)) diff --git a/pygmt/src/inset.py b/pygmt/src/inset.py index 720cf83a0ba..be0e4b40cce 100644 --- a/pygmt/src/inset.py +++ b/pygmt/src/inset.py @@ -134,7 +134,7 @@ def inset(self, **kwargs): >>> fig.logo(position="jBR+o0.2c+w3c") >>> fig.show() """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() with Session() as lib: try: lib.call_module(module="inset", args=["begin", *build_arg_list(kwargs)]) diff --git a/pygmt/src/legend.py b/pygmt/src/legend.py index 16d58a08571..10cc69e3843 100644 --- a/pygmt/src/legend.py +++ b/pygmt/src/legend.py @@ -82,7 +82,7 @@ def legend( {perspective} {transparency} """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() if kwargs.get("D") is None: kwargs["D"] = position diff --git a/pygmt/src/logo.py b/pygmt/src/logo.py index 1174f227604..0a3f394b79e 100644 --- a/pygmt/src/logo.py +++ b/pygmt/src/logo.py @@ -54,6 +54,6 @@ def logo(self, **kwargs): {panel} {transparency} """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() with Session() as lib: lib.call_module(module="logo", args=build_arg_list(kwargs)) diff --git a/pygmt/src/meca.py b/pygmt/src/meca.py index 9abf921ffcf..797a2f1facb 100644 --- a/pygmt/src/meca.py +++ b/pygmt/src/meca.py @@ -337,7 +337,7 @@ def meca( # noqa: PLR0913 {perspective} {transparency} """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() # Determine the focal mechanism convention from the input data or parameters. _convention = _get_focal_convention(spec, convention, component) # Preprocess the input data. diff --git a/pygmt/src/plot.py b/pygmt/src/plot.py index 93c612e29ec..33017624245 100644 --- a/pygmt/src/plot.py +++ b/pygmt/src/plot.py @@ -230,7 +230,7 @@ def plot( # noqa: PLR0912 """ # TODO(GMT>6.5.0): Remove the note for the upstream bug of the "straight_line" # parameter. - kwargs = self._preprocess(**kwargs) + self._activate_figure() kind = data_kind(data) if kind == "empty": # Data is given via a series of vectors. diff --git a/pygmt/src/plot3d.py b/pygmt/src/plot3d.py index f50894ec060..3533a952a28 100644 --- a/pygmt/src/plot3d.py +++ b/pygmt/src/plot3d.py @@ -208,7 +208,7 @@ def plot3d( # noqa: PLR0912 """ # TODO(GMT>6.5.0): Remove the note for the upstream bug of the "straight_line" # parameter. - kwargs = self._preprocess(**kwargs) + self._activate_figure() kind = data_kind(data) if kind == "empty": # Data is given via a series of vectors. diff --git a/pygmt/src/psconvert.py b/pygmt/src/psconvert.py index c08cbe763fe..2524060a0a6 100644 --- a/pygmt/src/psconvert.py +++ b/pygmt/src/psconvert.py @@ -108,7 +108,7 @@ def psconvert(self, **kwargs): ``prefix`` parameter. {verbose} """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() # Default cropping the figure to True if kwargs.get("A") is None: kwargs["A"] = "" diff --git a/pygmt/src/rose.py b/pygmt/src/rose.py index cc1bd80e4da..09c723de773 100644 --- a/pygmt/src/rose.py +++ b/pygmt/src/rose.py @@ -199,8 +199,7 @@ def rose( {transparency} {wrap} """ - - kwargs = self._preprocess(**kwargs) + self._activate_figure() with Session() as lib: with lib.virtualfile_in( diff --git a/pygmt/src/shift_origin.py b/pygmt/src/shift_origin.py index 21287847d4d..b351b7aadf0 100644 --- a/pygmt/src/shift_origin.py +++ b/pygmt/src/shift_origin.py @@ -98,7 +98,7 @@ def shift_origin( ... fig.basemap(region=[0, 5, 0, 5], projection="X5c/5c", frame=True) >>> fig.show() """ - self._preprocess() + self._activate_figure() kwdict = {"T": True, "X": xshift, "Y": yshift} with Session() as lib: diff --git a/pygmt/src/solar.py b/pygmt/src/solar.py index cc2720f6b01..96fada2b918 100644 --- a/pygmt/src/solar.py +++ b/pygmt/src/solar.py @@ -95,7 +95,7 @@ def solar( >>> # show the plot >>> fig.show() """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() if kwargs.get("T") is not None: msg = "Use 'terminator' and 'terminator_datetime' instead of 'T'." raise GMTInvalidInput(msg) diff --git a/pygmt/src/subplot.py b/pygmt/src/subplot.py index fbd87531674..f96bde809b5 100644 --- a/pygmt/src/subplot.py +++ b/pygmt/src/subplot.py @@ -145,7 +145,7 @@ def subplot(self, nrows=1, ncols=1, **kwargs): [no heading]. Font is determined by setting :gmt-term:`FONT_HEADING`. {verbose} """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() if nrows < 1 or ncols < 1: msg = "Please ensure that both 'nrows'>=1 and 'ncols'>=1." @@ -224,7 +224,7 @@ def set_panel(self, panel=None, **kwargs): {verbose} """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() with Session() as lib: lib.call_module( diff --git a/pygmt/src/ternary.py b/pygmt/src/ternary.py index 79289a46244..2880894d2bc 100644 --- a/pygmt/src/ternary.py +++ b/pygmt/src/ternary.py @@ -81,7 +81,7 @@ def ternary( {perspective} {transparency} """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() # -Lalabel/blabel/clabel. '-' means skipping the label. labels = (alabel, blabel, clabel) diff --git a/pygmt/src/text.py b/pygmt/src/text.py index eb232430439..6869bee2beb 100644 --- a/pygmt/src/text.py +++ b/pygmt/src/text.py @@ -179,7 +179,7 @@ def text_( # noqa: PLR0912 ``x``/``y`` and ``text``. {wrap} """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() # Ensure inputs are either textfiles, x/y/text, or position/text if ( diff --git a/pygmt/src/tilemap.py b/pygmt/src/tilemap.py index b2b727ea287..7e98f512890 100644 --- a/pygmt/src/tilemap.py +++ b/pygmt/src/tilemap.py @@ -105,7 +105,7 @@ def tilemap( kwargs : dict Extra keyword arguments to pass to :meth:`pygmt.Figure.grdimage`. """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() raster = load_tile_map( region=region, diff --git a/pygmt/src/timestamp.py b/pygmt/src/timestamp.py index 13f278b2816..b72daf9fb73 100644 --- a/pygmt/src/timestamp.py +++ b/pygmt/src/timestamp.py @@ -76,7 +76,7 @@ def timestamp( >>> fig.timestamp(label="Powered by PyGMT") >>> fig.show() """ - self._preprocess() + self._activate_figure() # Build the options passed to the "plot" module kwdict: dict = {"T": True, "U": ""} diff --git a/pygmt/src/velo.py b/pygmt/src/velo.py index 066a91b10e7..d5826c956ab 100644 --- a/pygmt/src/velo.py +++ b/pygmt/src/velo.py @@ -239,7 +239,7 @@ def velo(self, data: PathLike | TableLike | None = None, **kwargs): {perspective} {transparency} """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() if kwargs.get("S") is None or ( kwargs.get("S") is not None and not isinstance(kwargs["S"], str) diff --git a/pygmt/src/vlines.py b/pygmt/src/vlines.py index 7f1919baa9c..1e889a40cd6 100644 --- a/pygmt/src/vlines.py +++ b/pygmt/src/vlines.py @@ -80,7 +80,7 @@ def vlines( >>> fig.legend() >>> fig.show() """ - self._preprocess() + self._activate_figure() # Determine the y limits from the current plot region if not specified. if ymin is None or ymax is None: diff --git a/pygmt/src/wiggle.py b/pygmt/src/wiggle.py index c507d13f9f8..904ffa08c52 100644 --- a/pygmt/src/wiggle.py +++ b/pygmt/src/wiggle.py @@ -98,7 +98,7 @@ def wiggle( {transparency} {wrap} """ - kwargs = self._preprocess(**kwargs) + self._activate_figure() if fillpositive or fillnegative: kwargs["G"] = []