@@ -972,7 +972,8 @@ def savefig(self, *args, **kwargs):
972972 call signature::
973973
974974 savefig(fname, dpi=None, facecolor='w', edgecolor='w',
975- orientation='portrait', papertype=None, format=None):
975+ orientation='portrait', papertype=None, format=None,
976+ transparent=False):
976977
977978 Save the current figure.
978979
@@ -1006,14 +1007,36 @@ def savefig(self, *args, **kwargs):
10061007 *format*:
10071008 One of the file extensions supported by the active
10081009 backend. Most backends support png, pdf, ps, eps and svg.
1010+
1011+ *transparent*:
1012+ If *True*, the figure patch and axes patches will all be
1013+ transparent. This is useful, for example, for displaying
1014+ a plot on top of a colored background on a web page. The
1015+ transparency of these patches will be restored to their
1016+ original values upon exit of this function.
10091017 """
10101018
10111019 for key in ('dpi' , 'facecolor' , 'edgecolor' ):
10121020 if not kwargs .has_key (key ):
10131021 kwargs [key ] = rcParams ['savefig.%s' % key ]
10141022
1023+ transparent = kwargs .pop ('transparent' , False )
1024+ if transparent :
1025+ original_figure_alpha = self .figurePatch .get_alpha ()
1026+ self .figurePatch .set_alpha (0.0 )
1027+ original_axes_alpha = []
1028+ for ax in self .axes :
1029+ axesPatch = ax .get_frame ()
1030+ original_axes_alpha .append (axesPatch .get_alpha ())
1031+ axesPatch .set_alpha (0.0 )
1032+
10151033 self .canvas .print_figure (* args , ** kwargs )
10161034
1035+ if transparent :
1036+ self .figurePatch .set_alpha (original_figure_alpha )
1037+ for ax , alpha in zip (self .axes , original_axes_alpha ):
1038+ ax .get_frame ().set_alpha (alpha )
1039+
10171040 def colorbar (self , mappable , cax = None , ax = None , ** kw ):
10181041 if ax is None :
10191042 ax = self .gca ()
0 commit comments