[EHN] Add frameon and savefig.frameon to rcParams #1875

Merged
merged 2 commits into from Apr 2, 2013
View
@@ -259,7 +259,7 @@ def __init__(self,
facecolor=None, # defaults to rc figure.facecolor
edgecolor=None, # defaults to rc figure.edgecolor
linewidth=0.0, # the default linewidth of the frame
- frameon=True, # whether or not to draw the figure frame
+ frameon=None, # whether or not to draw the figure frame
subplotpars=None, # default to rc
tight_layout=None, # default to rc figure.autolayout
):
@@ -302,6 +302,8 @@ def __init__(self,
facecolor = rcParams['figure.facecolor']
if edgecolor is None:
edgecolor = rcParams['figure.edgecolor']
+ if frameon is None:
+ frameon = rcParams['figure.frameon']
self.dpi_scale_trans = Affine2D()
self.dpi = dpi
@@ -1306,7 +1308,8 @@ def savefig(self, *args, **kwargs):
savefig(fname, dpi=None, facecolor='w', edgecolor='w',
orientation='portrait', papertype=None, format=None,
- transparent=False, bbox_inches=None, pad_inches=0.1)
+ transparent=False, bbox_inches=None, pad_inches=0.1,
+ frameon=None)
The output formats available depend on the backend being used.
@@ -1355,6 +1358,11 @@ def savefig(self, *args, **kwargs):
transparency of these patches will be restored to their
original values upon exit of this function.
+ *frameon*:
+ 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*:
Bbox in inches. Only the given portion of the figure is
saved. If 'tight', try to figure out the tight bbox of
@@ -1371,8 +1379,9 @@ def savefig(self, *args, **kwargs):
"""
kwargs.setdefault('dpi', rcParams['savefig.dpi'])
-
+ frameon = kwargs.pop('frameon', rcParams['savefig.frameon'])
transparent = kwargs.pop('transparent', False)
+
if transparent:
kwargs.setdefault('facecolor', 'none')
kwargs.setdefault('edgecolor', 'none')
@@ -1387,8 +1396,15 @@ def savefig(self, *args, **kwargs):
kwargs.setdefault('facecolor', rcParams['savefig.facecolor'])
kwargs.setdefault('edgecolor', rcParams['savefig.edgecolor'])
+ if frameon:
+ original_frameon = self.get_frameon()
+ self.set_frameon(frameon)
+
self.canvas.print_figure(*args, **kwargs)
+ if frameon:
+ self.set_frameon(original_frameon)
+
if transparent:
for ax, cc in zip(self.axes, original_axes_colors):
ax.patch.set_facecolor(cc[0])
@@ -658,6 +658,7 @@ def __call__(self, s):
'figure.dpi': [80, validate_float], # DPI
'figure.facecolor': ['0.75', validate_color], # facecolor; scalar gray
'figure.edgecolor': ['w', validate_color], # edgecolor; white
+ 'figure.frameon': [True, validate_bool],
'figure.autolayout': [False, validate_bool],
'figure.subplot.left': [0.125, ValidateInterval(0, 1, closedmin=True,
@@ -677,6 +678,7 @@ def __call__(self, s):
'savefig.dpi': [100, validate_float], # DPI
'savefig.facecolor': ['w', validate_color], # facecolor; white
'savefig.edgecolor': ['w', validate_color], # edgecolor; white
+ 'savefig.frameon': [True, validate_bool],
'savefig.orientation': ['portrait', validate_orientation], # edgecolor;
#white
# what to add to extensionless filenames