Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added savefig.pad_inches; refactored savefig.bbox

  • Loading branch information...
commit 69dcec448614b23fb806cdf6d01d46e4f16068a1 1 parent 4047815
Amy authored July 13, 2012
13  lib/matplotlib/backend_bases.py
@@ -1978,11 +1978,11 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
1978 1978
         *bbox_inches*
1979 1979
             Bbox in inches. Only the given portion of the figure is
1980 1980
             saved. If 'tight', try to figure out the tight bbox of
1981  
-            the figure.
  1981
+            the figure. If None, use savefig.bbox
1982 1982
 
1983 1983
         *pad_inches*
1984 1984
             Amount of padding around the figure when bbox_inches is
1985  
-            'tight'.
  1985
+            'tight'. If None, use savefig.pad_inches
1986 1986
 
1987 1987
         *bbox_extra_artists*
1988 1988
             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',
2013 2013
         self.figure.set_facecolor(facecolor)
2014 2014
         self.figure.set_edgecolor(edgecolor)
2015 2015
 
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
+
2017 2020
 
2018 2021
         if bbox_inches:
2019 2022
             # call adjust_bbox to save only the given area
@@ -2054,8 +2057,10 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
2054 2057
 
2055 2058
                     bbox_inches = Bbox.union([bbox_inches, bbox_inches1])
2056 2059
 
  2060
+                pad = kwargs.pop("pad_inches", None)
  2061
+                if pad == None:
  2062
+                    pad = rcParams['savefig.pad_inches']
2057 2063
 
2058  
-                pad = kwargs.pop("pad_inches", 0.1)
2059 2064
                 bbox_inches = bbox_inches.padded(pad)
2060 2065
 
2061 2066
             restore_bbox = tight_bbox.adjust_bbox(self.figure, format,
13  lib/matplotlib/rcsetup.py
@@ -328,11 +328,11 @@ def validate_hinting(s):
328 328
 def validate_bbox(s):
329 329
     if type(s) is str:
330 330
         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'")
336 336
 
337 337
 
338 338
 
@@ -559,7 +559,8 @@ def __call__(self, s):
559 559
     'savefig.orientation' : ['portrait', validate_orientation],  # edgecolor; white
560 560
     'savefig.extension'   : ['png', deprecate_savefig_extension], # what to add to extensionless filenames
561 561
     '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],
563 564
 
564 565
     'tk.window_focus'    : [False, validate_bool],  # Maintain shell focus for TkAgg
565 566
     'tk.pythoninspect'   : [False, validate_tkpythoninspect],  # obsolete
11  matplotlibrc.template
@@ -346,11 +346,12 @@ text.hinting_factor : 8 # Specifies the amount of softness for hinting in the
346 346
 # the default savefig params can be different from the display params
347 347
 # Eg, you may want a higher resolution, or to make the figure
348 348
 # 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'
354 355
 
355 356
 # tk backend params
356 357
 #tk.window_focus   : False    # Maintain shell focus for TkAgg

0 notes on commit 69dcec4

Amy

Whitespace change here

Please sign in to comment.
Something went wrong with that request. Please try again.