8000 Added savefig.pad_inches; refactored savefig.bbox · matplotlib/matplotlib@69dcec4 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 69dcec4

Browse files
committed
Added savefig.pad_inches; refactored savefig.bbox
1 parent 4047815 commit 69dcec4

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,11 +1978,11 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
19781978
*bbox_inches*
19791979
Bbox in inches. Only the given portion of the figure is
19801980
saved. If 'tight', try to figure out the tight bbox of
1981-
the figure.
1981+
the figure. If None, use savefig.bbox
19821982
19831983
*pad_inches*
19841984
Amount of padding around the figure when bbox_inches is
1985-
'tight'.
1985+
'tight'. If None, use savefig.pad_inches
19861986
19871987
*bbox_extra_artists*
19881988
A list of extra artists that will be considered when the
@@ -2013,7 +2013,10 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
20132013
self.figure.set_facecolor(facecolor)
20142014
self.figure.set_edgecolor(edgecolor)
20152015

2016-
bbox_inches = kwargs.pop("bbox_inches", rcParams['savefig.bbox'])
2016+
bbox_inches = kwargs.pop("bbox_inches", None)
2017+
if bbox_inches == None:
2018+
bbox_inches = rcParams['savefig.bbox']
2019+
20172020

20182021
if bbox_inches:
20192022
# call adjust_bbox to save only the given area
@@ -2054,8 +2057,10 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
20542057

20552058
bbox_inches = Bbox.union([bbox_inches, bbox_inches1])
20562059

2060+
pad = kwargs.pop("pad_inches", None)
2061+
if pad == None:
2062+
pad = rcParams['savefig.pad_inches']
20572063

2058-
pad = kwargs.pop("pad_inches", 0.1)
20592064
bbox_inches = bbox_inches.padded(pad)
20602065

20612066
restore_bbox = tight_bbox.adjust_bbox(self.figure, format,

lib/matplotlib/rcsetup.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,11 @@ def validate_hinting(s):
328328
def validate_bbox(s):
329329
if type(s) is str:
330330
s = s.lower()
331-
if s in ('tight'):
332-
return s
333-
if s in ('auto'):
334-
return None
335-
raise ValueError("bbox_inches should be 'auto' or 'tight'")
331+
if s == 'tight':
332+
return s
333+
if s == 'default':
334+
return None
335+
raise ValueError("bbox should be 'tight' or 'default'")
336336

337337

338338

@@ -559,7 +559,8 @@ def __call__(self, s):
559559
'savefig.orientation' : ['portrait', validate_orientation], # edgecolor; white
560560
'savefig.extension' : ['png', deprecate_savefig_extension], # what to add to extensionless filenames
561561
'savefig.format' : ['png', str], # value checked by backend at runtime
562-
'savefig.bbox' : [None, validate_bbox], # options are tight or auto. Auto validates to 'None'
562+
'savefig.bbox' : [None, validate_bbox], # options are 'tight', or 'default'. 'default' validates to None.
563+
'savefig.pad_inches' : [0.1, validate_float],
563564

564565
'tk.window_focus' : [False, validate_bool], # Maintain shell focus for TkAgg
565566
'tk.pythoninspect' : [False, validate_tkpythoninspect], # obsolete

matplotlibrc.template

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,12 @@ text.hinting_factor : 8 # Specifies the amount of softness for hinting in the
346346
# the default savefig params can be different from the display params
347347
# Eg, you may want a higher resolution, or to make the figure
348348
# background white
349-
#savefig.dpi : 100 # figure dots per inch
350-
#savefig.facecolor : white # figure facecolor when saving
351-
#savefig.edgecolor : white # figure edgecolor when saving
352-
#savefig.format : png # png, ps, pdf, svg
353-
#savefig.bbox : auto # tight, auto. When set to 'tight', will set the figure's bounding box to 'tight' and recalculate. When set to 'auto', it will use the automatic bounding box calculation.
349+
#savefig.dpi : 100 # figure dots per inch
350+
#savefig.facecolor : white # figure facecolor when saving
351+
#savefig.edgecolor : white # figure edgecolor when saving
352+
#savefig.format : png # png, ps, pdf, svg
353+
#savefig.bbox : default # 'tight' or 'default'.
354+
#savefig.pad_inches : 0.1 # Padding to be used when bbox is set to 'tight'
354355

355356
# tk backend params
356357
#tk.window_focus : False # Maintain shell focus for TkAgg

0 commit comments

Comments
 (0)
0