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

Skip to content

Commit 1f25f15

Browse files
author
patchen
committed
Added whats new and validation for figure.savefig dpi change
1 parent 60f998b commit 1f25f15

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Updated Figure.savefig()
2+
------------------------
3+
4+
Added support to save the figure with the same dpi as the figure on the screen using dpi='figure'
5+
6+
Example:
7+
f = plt.figure(dpi=25) # dpi set to 25
8+
S = plt.scatter([1,2,3],[4,5,6])
9+
f.savefig('output.png', dpi='figure') # output savefig dpi set to 25 (same as figure)

lib/matplotlib/rcsetup.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ def validate_float_or_None(s):
117117
except ValueError:
118118
raise ValueError('Could not convert "%s" to float' % s)
119119

120+
def validate_dpi(s):
121+
"""confirm s is string 'figure' or convert s to float or raise"""
122+
if s == 'figure':
123+
return s
124+
try:
125+
return float(s)
126+
except ValueError:
127+
raise ValueError('"%s" is not string "figure" or'
128+
' could not convert "%s" to float' % (s, s))
120129

121130
def validate_int(s):
122131
"""convert s to int or raise"""
@@ -749,7 +758,7 @@ def __call__(self, s):
749758
closedmax=False)],
750759

751760
## Saving figure's properties
752-
'savefig.dpi': [100, validate_float], # DPI
761+
'savefig.dpi': [100, validate_dpi], # DPI
753762
'savefig.facecolor': ['w', validate_color], # facecolor; white
754763
'savefig.edgecolor': ['w', validate_color], # edgecolor; white
755764
'savefig.frameon': [True, validate_bool],

0 commit comments

Comments
 (0)