From 897c4974dd3cca3444f157b899e7e6ff720087c1 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 18 Jul 2018 15:19:26 +0200 Subject: [PATCH] Deprecate frameon kwarg and rcParam to savefig. ``frameon = False`` has *never* worked since its introduction in 2013 due to the buggy implementation that only took it into account if True: if frameon: original_frameon = self.get_frameon() self.set_frameon(frameon) (despite the doc stating otherwise). One can also set the facecolor kwarg or savefig.facecolor rcParam to fully transparent for the same effect. --- doc/api/next_api_changes/2018-09-25-AL.rst | 6 ++++++ lib/matplotlib/__init__.py | 1 + lib/matplotlib/figure.py | 17 +++++++++-------- .../mpl-data/stylelib/_classic_test.mplstyle | 1 - .../mpl-data/stylelib/classic.mplstyle | 1 - matplotlibrc.template | 1 - 6 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 doc/api/next_api_changes/2018-09-25-AL.rst diff --git a/doc/api/next_api_changes/2018-09-25-AL.rst b/doc/api/next_api_changes/2018-09-25-AL.rst new file mode 100644 index 000000000000..75edb07c024d --- /dev/null +++ b/doc/api/next_api_changes/2018-09-25-AL.rst @@ -0,0 +1,6 @@ +Deprecations +```````````` + +The ``frameon`` kwarg to ``savefig`` and the ``savefig.frameon`` rcParam +are deprecated. To emulate ``frameon = False``, set ``facecolor`` to fully +transparent (``"none"``, or ``(0, 0, 0, 0)``). diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 489756d9f57a..bc1f0d999331 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -704,6 +704,7 @@ def gen_candidates(): # Values are tuples of (version,) _deprecated_remain_as_none = { 'text.latex.unicode': ('3.0',), + 'savefig.frameon': ('3.1',), } diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 653455b0b6dd..da4d146fc10c 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -2020,7 +2020,7 @@ def add_axobserver(self, func): """Whenever the axes state change, ``func(self)`` will be called.""" self._axobservers.append(func) - def savefig(self, fname, *, frameon=None, transparent=None, **kwargs): + def savefig(self, fname, *, transparent=None, **kwargs): """ Save the current figure. @@ -2102,11 +2102,6 @@ def savefig(self, fname, *, frameon=None, transparent=None, **kwargs): transparency of these patches will be restored to their original values upon exit of this function. - frameon : bool - If *True*, the figure patch will be colored, if *False*, the - figure background will be transparent. If not provided, the - rcParam 'savefig.frameon' will be used. - bbox_inches : str or `~matplotlib.transforms.Bbox`, optional Bbox in inches. Only the given portion of the figure is saved. If 'tight', try to figure out the tight bbox of @@ -2138,8 +2133,14 @@ def savefig(self, fname, *, frameon=None, transparent=None, **kwargs): """ kwargs.setdefault('dpi', rcParams['savefig.dpi']) - if frameon is None: - frameon = rcParams['savefig.frameon'] + if "frameon" in kwargs: + cbook.warn_deprecated("3.1", name="frameon", obj_type="kwarg", + alternative="facecolor") + frameon = kwargs.pop("frameon") + if frameon is None: + frameon = dict.__getitem__(rcParams, 'savefig.frameon') + else: + frameon = False # Won't pass "if frameon:" below. if transparent is None: transparent = rcParams['savefig.transparent'] diff --git a/lib/matplotlib/mpl-data/stylelib/_classic_test.mplstyle b/lib/matplotlib/mpl-data/stylelib/_classic_test.mplstyle index b6807990e764..5ae7b7a39e56 100644 --- a/lib/matplotlib/mpl-data/stylelib/_classic_test.mplstyle +++ b/lib/matplotlib/mpl-data/stylelib/_classic_test.mplstyle @@ -418,7 +418,6 @@ savefig.pad_inches : 0.1 # Padding to be used when bbox is set to 'tight' savefig.jpeg_quality: 95 # when a jpeg is saved, the default quality parameter. savefig.transparent : False # setting that controls whether figures are saved with a # transparent background by default -savefig.frameon : True savefig.orientation : portrait # ps backend params diff --git a/lib/matplotlib/mpl-data/stylelib/classic.mplstyle b/lib/matplotlib/mpl-data/stylelib/classic.mplstyle index 48f5a4521991..f52170541c81 100644 --- a/lib/matplotlib/mpl-data/stylelib/classic.mplstyle +++ b/lib/matplotlib/mpl-data/stylelib/classic.mplstyle @@ -422,7 +422,6 @@ savefig.pad_inches : 0.1 # Padding to be used when bbox is set to 'tight' savefig.jpeg_quality: 95 # when a jpeg is saved, the default quality parameter. savefig.transparent : False # setting that controls whether figures are saved with a # transparent background by default -savefig.frameon : True savefig.orientation : portrait # ps backend params diff --git a/matplotlibrc.template b/matplotlibrc.template index df9ed2c7bcfc..c06ec1f8f9c3 100644 --- a/matplotlibrc.template +++ b/matplotlibrc.template @@ -540,7 +540,6 @@ ## leave empty to always use current working directory #savefig.transparent : False ## setting that controls whether figures are saved with a ## transparent background by default -#savefig.frameon : True ## enable frame of figure when saving #savefig.orientation : portrait ## Orientation of saved figure ### tk backend params