Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand All @@ -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')
Expand All @@ -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])
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down