Permalink
Browse files

Added savefig.bbox option to matplotlibrc

Allows the user to set the bounding box to 'tight,' which will override the defaults when saving from the interface.
  • Loading branch information...
1 parent 8c57e4f commit 40478157188d9f558c98a3cc1b21f307b490d2d3 @oxling committed Jul 10, 2012
Showing with 15 additions and 1 deletion.
  1. +3 −1 lib/matplotlib/backend_bases.py
  2. +11 −0 lib/matplotlib/rcsetup.py
  3. +1 −0 matplotlibrc.template
@@ -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)
@@ -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()
@@ -2011,7 +2013,7 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
self.figure.set_facecolor(facecolor)
self.figure.set_edgecolor(edgecolor)
- bbox_inches = kwargs.pop("bbox_inches", None)
+ bbox_inches = kwargs.pop("bbox_inches", rcParams['savefig.bbox'])
if bbox_inches:
# call adjust_bbox to save only the given area
View
@@ -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 in ('tight'):
+ return s
+ if s in ('auto'):
+ return None
+ raise ValueError("bbox_inches should be 'auto' or 'tight'")
+
+
class ValidateInterval:
"""
@@ -549,6 +559,7 @@ 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 auto. Auto validates to 'None'
'tk.window_focus' : [False, validate_bool], # Maintain shell focus for TkAgg
'tk.pythoninspect' : [False, validate_tkpythoninspect], # obsolete
View
@@ -350,6 +350,7 @@ text.hinting_factor : 8 # Specifies the amount of softness for hinting in the
#savefig.facecolor : white # figure facecolor when saving
#savefig.edgecolor : white # figure edgecolor when saving
#savefig.format : png # png, ps, pdf, svg
+#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.
# tk backend params
#tk.window_focus : False # Maintain shell focus for TkAgg

0 comments on commit 4047815

Please sign in to comment.