Permalink
Browse files

Merge pull request #1004 from oxling/bbox_merge

Added savefig.bbox option to matplotlibrc
  • Loading branch information...
2 parents 63e406b + e6651c3 commit 561d0dacaabfbbc26e3899e22ac4f47faf92a853 @WeatherGod WeatherGod committed Jul 23, 2012
Showing with 36 additions and 7 deletions.
  1. +8 −0 doc/users/whats_new.rst
  2. +10 −3 lib/matplotlib/backend_bases.py
  3. +12 −0 lib/matplotlib/rcsetup.py
  4. +6 −4 matplotlibrc.template
@@ -57,6 +57,14 @@ minimum and maximum colorbar extensions.
plt.show()
+
+Set default bounding box in matplotlibrc
+------------------------------------------
+
+Two new defaults are available in the matplotlibrc configuration file.
+These are savefig.bbox, which can be set to 'standard' or 'tight,' and
+savefig.pad_inches, which controls the bounding box padding.
+
.. _whats-new-1-1:
new in matplotlib-1.1
@@ -230,6 +230,7 @@ def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
:meth:`draw_quad_mesh` that generates paths and then calls
:meth:`draw_path_collection`.
"""
+
from matplotlib.collections import QuadMesh
paths = QuadMesh.convert_mesh_to_paths(
meshWidth, meshHeight, coordinates)
@@ -1977,11 +1978,11 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
*bbox_inches*
Bbox in inches. Only the given portion of the figure is
saved. If 'tight', try to figure out the tight bbox of
- the figure.
+ the figure. If None, use savefig.bbox
*pad_inches*
Amount of padding around the figure when bbox_inches is
- 'tight'.
+ 'tight'. If None, use savefig.pad_inches
*bbox_extra_artists*
A list of extra artists that will be considered when the
@@ -2003,6 +2004,7 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
if dpi is None:
dpi = rcParams['savefig.dpi']
+
origDPI = self.figure.dpi
origfacecolor = self.figure.get_facecolor()
origedgecolor = self.figure.get_edgecolor()
@@ -2012,6 +2014,9 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
self.figure.set_edgecolor(edgecolor)
bbox_inches = kwargs.pop("bbox_inches", None)
+ if bbox_inches is None:
+ bbox_inches = rcParams['savefig.bbox']
+
if bbox_inches:
# call adjust_bbox to save only the given area
@@ -2052,8 +2057,10 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
bbox_inches = Bbox.union([bbox_inches, bbox_inches1])
+ pad = kwargs.pop("pad_inches", None)
+ if pad is None:
+ pad = rcParams['savefig.pad_inches']
- pad = kwargs.pop("pad_inches", 0.1)
bbox_inches = bbox_inches.padded(pad)
restore_bbox = tight_bbox.adjust_bbox(self.figure, format,
@@ -325,6 +325,16 @@ def validate_hinting(s):
validate_movie_frame_fmt = ValidateInStrings('animation.frame_format',
['png', 'jpeg', 'tiff', 'raw', 'rgba'])
+def validate_bbox(s):
+ if type(s) is str:
+ s = s.lower()
+ if s == 'tight':
+ return s
+ if s == 'standard':
+ return None
+ raise ValueError("bbox should be 'tight' or 'standard'")
+
+
class ValidateInterval:
"""
@@ -549,6 +559,8 @@ def __call__(self, s):
'savefig.orientation' : ['portrait', validate_orientation], # edgecolor; white
'savefig.extension' : ['png', deprecate_savefig_extension], # what to add to extensionless filenames
'savefig.format' : ['png', str], # value checked by backend at runtime
+ 'savefig.bbox' : [None, validate_bbox], # options are 'tight', or 'standard'. 'standard' validates to None.
+ 'savefig.pad_inches' : [0.1, validate_float],
'tk.window_focus' : [False, validate_bool], # Maintain shell focus for TkAgg
'tk.pythoninspect' : [False, validate_tkpythoninspect], # obsolete
View
@@ -346,10 +346,12 @@ text.hinting_factor : 8 # Specifies the amount of softness for hinting in the
# the default savefig params can be different from the display params
# Eg, you may want a higher resolution, or to make the figure
# background white
-#savefig.dpi : 100 # figure dots per inch
-#savefig.facecolor : white # figure facecolor when saving
-#savefig.edgecolor : white # figure edgecolor when saving
-#savefig.format : png # png, ps, pdf, svg
+#savefig.dpi : 100 # figure dots per inch
+#savefig.facecolor : white # figure facecolor when saving
+#savefig.edgecolor : white # figure edgecolor when saving
+#savefig.format : png # png, ps, pdf, svg
+#savefig.bbox : standard # 'tight' or 'standard'.
+#savefig.pad_inches : 0.1 # Padding to be used when bbox is set to 'tight'
# tk backend params
#tk.window_focus : False # Maintain shell focus for TkAgg

0 comments on commit 561d0da

Please sign in to comment.