Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f275b21

Browse files
committed
Merge pull request #1875 from Tillsten/add_frameon_rc
[EHN] Add frameon and savefig.frameon to rcParams
2 parents 32bed39 + 9307d3a commit f275b21

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

lib/matplotlib/figure.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def __init__(self,
259259
facecolor=None, # defaults to rc figure.facecolor
260260
edgecolor=None, # defaults to rc figure.edgecolor
261261
linewidth=0.0, # the default linewidth of the frame
262-
frameon=True, # whether or not to draw the figure frame
262+
frameon=None, # whether or not to draw the figure frame
263263
subplotpars=None, # default to rc
264264
tight_layout=None, # default to rc figure.autolayout
265265
):
@@ -302,6 +302,8 @@ def __init__(self,
302302
facecolor = rcParams['figure.facecolor']
303303
if edgecolor is None:
304304
edgecolor = rcParams['figure.edgecolor']
305+
if frameon is None:
306+
frameon = rcParams['figure.frameon']
305307

306308
self.dpi_scale_trans = Affine2D()
307309
self.dpi = dpi
@@ -1306,7 +1308,8 @@ def savefig(self, *args, **kwargs):
13061308
13071309
savefig(fname, dpi=None, facecolor='w', edgecolor='w',
13081310
orientation='portrait', papertype=None, format=None,
1309-
transparent=False, bbox_inches=None, pad_inches=0.1)
1311+
transparent=False, bbox_inches=None, pad_inches=0.1,
1312+
frameon=None)
13101313
13111314
The output formats available depend on the backend being used.
13121315
@@ -1355,6 +1358,11 @@ def savefig(self, *args, **kwargs):
13551358
transparency of these patches will be restored to their
13561359
original values upon exit of this function.
13571360
1361+
*frameon*:
1362+
If *True*, the figure patch will be colored, if *False*, the
1363+
figure background will be transparent. If not provided, the
1364+
rcParam 'savefig.frameon' will be used.
1365+
13581366
*bbox_inches*:
13591367
Bbox in inches. Only the given portion of the figure is
13601368
saved. If 'tight', try to figure out the tight bbox of
@@ -1371,8 +1379,9 @@ def savefig(self, *args, **kwargs):
13711379
"""
13721380

13731381
kwargs.setdefault('dpi', rcParams['savefig.dpi'])
1374-
1382+
frameon = kwargs.pop('frameon', rcParams['savefig.frameon'])
13751383
transparent = kwargs.pop('transparent', False)
1384+
13761385
if transparent:
13771386
kwargs.setdefault('facecolor', 'none')
13781387
kwargs.setdefault('edgecolor', 'none')
@@ -1387,8 +1396,15 @@ def savefig(self, *args, **kwargs):
13871396
kwargs.setdefault('facecolor', rcParams['savefig.facecolor'])
13881397
kwargs.setdefault('edgecolor', rcParams['savefig.edgecolor'])
13891398

1399+
if frameon:
1400+
original_frameon = self.get_frameon()
1401+
self.set_frameon(frameon)
1402+
13901403
self.canvas.print_figure(*args, **kwargs)
13911404

1405+
if frameon:
1406+
self.set_frameon(original_frameon)
1407+
13921408
if transparent:
13931409
for ax, cc in zip(self.axes, original_axes_colors):
13941410
ax.patch.set_facecolor(cc[0])

lib/matplotlib/rcsetup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ def __call__(self, s):
658658
'figure.dpi': [80, validate_float], # DPI
659659
'figure.facecolor': ['0.75', validate_color], # facecolor; scalar gray
660660
'figure.edgecolor': ['w', validate_color], # edgecolor; white
661+
'figure.frameon': [True, validate_bool],
661662
'figure.autolayout': [False, validate_bool],
662663

663664
'figure.subplot.left': [0.125, ValidateInterval(0, 1, closedmin=True,
@@ -677,6 +678,7 @@ def __call__(self, s):
677678
'savefig.dpi': [100, validate_float], # DPI
678679
'savefig.facecolor': ['w', validate_color], # facecolor; white
679680
'savefig.edgecolor': ['w', validate_color], # edgecolor; white
681+
'savefig.frameon': [True, validate_bool],
680682
'savefig.orientation': ['portrait', validate_orientation], # edgecolor;
681683
#white
682684
# what to add to extensionless filenames

0 commit comments

Comments
 (0)