diff --git a/doc/api/api_changes.rst b/doc/api/api_changes.rst index d3bc6d242834..4c207c48e0b8 100644 --- a/doc/api/api_changes.rst +++ b/doc/api/api_changes.rst @@ -59,6 +59,9 @@ original location: thus `colorbar.ColorbarBase.outline` is now a `matplotlib.patches.Polygon` object. +* The rcParams `savefig.transparent` has been added to control + default transparency when saving figures. + .. _changes_in_1_3: diff --git a/doc/users/whats_new.rst b/doc/users/whats_new.rst index cbc1cf242c87..5172a413498a 100644 --- a/doc/users/whats_new.rst +++ b/doc/users/whats_new.rst @@ -44,6 +44,15 @@ and :func:`matplotlib.dates.datestr2num`. Support is also added to the unit conversion interfaces :class:`matplotlib.dates.DateConverter` and :class:`matplotlib.units.Registry`. +Configuration (rcParams) +------------------------ + +``savefig.transparent`` added +````````````````````````````` +Controls whether figures are saved with a transparent +background by default. Previously `savefig` always defaulted +to a non-transparent background. + .. _whats-new-1-3: new in matplotlib-1.3 diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 894303133a43..055b412ae184 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -1414,7 +1414,7 @@ def savefig(self, *args, **kwargs): kwargs.setdefault('dpi', rcParams['savefig.dpi']) frameon = kwargs.pop('frameon', rcParams['savefig.frameon']) - transparent = kwargs.pop('transparent', False) + transparent = kwargs.pop('transparent', rcParams['savefig.transparent']) if transparent: kwargs.setdefault('facecolor', 'none') diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index da53d5ece1d1..c6e075e6cd7c 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -563,7 +563,9 @@ def draw(): @docstring.copy_dedent(Figure.savefig) def savefig(*args, **kwargs): fig = gcf() - return fig.savefig(*args, **kwargs) + res = fig.savefig(*args, **kwargs) + draw() # need this if 'transparent=True' to reset colors + return res @docstring.copy_dedent(Figure.ginput) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 74b558237fca..6da1748d9c17 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -714,6 +714,7 @@ def __call__(self, s): 'savefig.pad_inches': [0.1, validate_float], # default directory in savefig dialog box 'savefig.directory': ['~', six.text_type], + 'savefig.transparent': [False, validate_bool], # Maintain shell focus for TkAgg 'tk.window_focus': [False, validate_bool], diff --git a/matplotlibrc.template b/matplotlibrc.template index 00f9e2a56138..44f94fdfd95d 100644 --- a/matplotlibrc.template +++ b/matplotlibrc.template @@ -377,6 +377,8 @@ backend : %(backend)s #savefig.jpeg_quality: 95 # when a jpeg is saved, the default quality parameter. #savefig.directory : ~ # default directory in savefig dialog box, # leave empty to always use current working directory +#savefig.transparent : False # setting that controls whether figures are saved with a + # transparent background by default # tk backend params #tk.window_focus : False # Maintain shell focus for TkAgg