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

Skip to content

Commit 53e44ef

Browse files
committed
fixed savefig dpi default for several backends
svn path=/trunk/matplotlib/; revision=2767
1 parent bf3116f commit 53e44ef

12 files changed

Lines changed: 34 additions & 21 deletions

lib/matplotlib/backend_bases.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ def get_width_height(self):
910910
(depending on the backend), truncated to integers"""
911911
return int(self.figure.bbox.width()), int(self.figure.bbox.height())
912912

913-
def print_figure(self, filename, dpi=300, facecolor='w', edgecolor='w',
913+
def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
914914
orientation='portrait', **kwargs):
915915
"""
916916
Render the figure to hardcopy. Set the figure patch face and edge
@@ -920,6 +920,7 @@ def print_figure(self, filename, dpi=300, facecolor='w', edgecolor='w',
920920
921921
filename - can also be a file object on image backends
922922
orientation - only currently applies to PostScript printing.
923+
dpi - the dots per inch to save the figure in; if None, use savefig.dpi
923924
"""
924925
pass
925926

lib/matplotlib/backends/backend_agg.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
from __future__ import division
7272

7373
import os, sys
74+
import matplotlib
7475
from matplotlib import verbose, rcParams
7576
from matplotlib.numerix import array, Float, zeros, transpose
7677
from matplotlib._image import fromarray
@@ -417,7 +418,7 @@ def buffer_rgba(self,x,y):
417418
'debug-annoying')
418419
return self.renderer.buffer_rgba(x,y)
419420

420-
def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
421+
def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
421422
orientation='portrait', **kwargs):
422423
"""
423424
Render the figure to hardcopy. Set the figure patch face and
@@ -434,6 +435,7 @@ def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
434435
"""
435436
if __debug__: verbose.report('FigureCanvasAgg.print_figure',
436437
'debug-annoying')
438+
if dpi is None: dpi = matplotlib.rcParams['savefig.dpi']
437439

438440
# store the orig figure dpi, color and size information so we
439441
# can restore them later. For image creation alone, this is

lib/matplotlib/backends/backend_fltkagg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ def blit(self,bbox):
246246

247247
show = draw
248248

249-
def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
249+
def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
250250
orientation='portrait', **kwargs):
251-
251+
if dpi is None: dpi = matplotlib.rcParams['savefig.dpi']
252252
agg = self.switch_backends(FigureCanvasAgg)
253253
agg.print_figure(filename, dpi, facecolor, edgecolor, orientation,
254254
**kwargs)

lib/matplotlib/backends/backend_gtk.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,10 @@ def expose_event(self, widget, event):
290290
return False # finish event propagation?
291291

292292

293-
def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
293+
def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
294294
orientation='portrait', **kwargs):
295295
# TODO - use gdk/cairo/agg print_figure?
296+
if dpi is None: dpi = matplotlib.rcParams['savefig.dpi']
296297
root, ext = os.path.splitext(filename)
297298
ext = ext[1:]
298299
if ext == '':

lib/matplotlib/backends/backend_gtkagg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ def blit(self, bbox=None):
9595
0, 0, 0, 0, w, h)
9696
if DEBUG: print 'FigureCanvasGTKAgg.done'
9797

98-
def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
98+
def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
9999
orientation='portrait', **kwargs):
100100
if DEBUG: print 'FigureCanvasGTKAgg.print_figure'
101101
# delete the renderer to prevent improper blitting after print
102102

103+
if dpi is None: dpi = matplotlib.rcParams['savefig.dpi']
103104
root, ext = os.path.splitext(filename)
104105
ext = ext.lower()[1:]
105106
if ext == 'jpg':

lib/matplotlib/backends/backend_qt4agg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,10 @@ def blit(self, bbox=None):
149149
l, t = bbox.ll().x().get(), bbox.ur().y().get()
150150
self.update(l, self.renderer.height-t, w, h)
151151

152-
def print_figure( self, filename, dpi=150, facecolor='w', edgecolor='w',
152+
def print_figure( self, filename, dpi=None, facecolor='w', edgecolor='w',
153153
orientation='portrait', **kwargs ):
154154
if DEBUG: print 'FigureCanvasQTAgg.print_figure'
155+
if dpi is None: dpi = matplotlib.rcParams['savefig.dpi']
155156
agg = self.switch_backends( FigureCanvasAgg )
156157
agg.print_figure( filename, dpi, facecolor, edgecolor, orientation,
157158
**kwargs )

lib/matplotlib/backends/backend_qtagg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@ def blit(self, bbox=None):
152152
self.replot = bbox
153153
self.repaint(False)
154154

155-
def print_figure( self, filename, dpi=150, facecolor='w', edgecolor='w',
155+
def print_figure( self, filename, dpi=None, facecolor='w', edgecolor='w',
156156
orientation='portrait', **kwargs ):
157157
if DEBUG: print 'FigureCanvasQTAgg.print_figure'
158+
if dpi is None: dpi = matplotlib.rcParams['savefig.dpi']
158159
agg = self.switch_backends( FigureCanvasAgg )
159160
agg.print_figure( filename, dpi, facecolor, edgecolor, orientation,
160161
**kwargs )

lib/matplotlib/backends/backend_template.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
from __future__ import division
4747

48+
import matplotlib
4849
from matplotlib._pylab_helpers import Gcf
4950
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
5051
FigureManagerBase, FigureCanvasBase
@@ -196,7 +197,7 @@ def draw(self):
196197
renderer = RendererTemplate()
197198
self.figure.draw(renderer)
198199

199-
def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
200+
def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
200201
orientation='portrait', **kwargs):
201202
"""
202203
Render the figure to hardcopy. Set the figure patch face and edge
@@ -210,6 +211,8 @@ def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
210211
An image backend does not need to do this since after the print the
211212
figure is done
212213
"""
214+
215+
if dpi is None: dpi = rcParams['savefig.dpi']
213216
# save the figure settings, GUI backends only
214217
#origDPI = self.figure.dpi.get()
215218
#origfacecolor = self.figure.get_facecolor()

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,10 @@ def get_tk_widget(self):
178178
"""
179179
return self._tkcanvas
180180

181-
def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
181+
def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
182182
orientation='portrait', **kwargs):
183183

184+
if dpi is None: dpi = rcParams['savefig.dpi']
184185
agg = self.switch_backends(FigureCanvasAgg)
185186
agg.print_figure(filename, dpi, facecolor, edgecolor, orientation,
186187
**kwargs)

lib/matplotlib/backends/backend_wx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,12 +926,12 @@ def gui_repaint(self, drawDC=None):
926926
drawDC.DrawBitmap(self.bitmap, 0, 0)
927927
drawDC.EndDrawing()
928928

929-
def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
929+
def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
930930
orientation='portrait', **kwargs):
931931
"""
932932
Render the figure to hardcopy
933933
"""
934-
934+
if dpi is None: dpi = matplotlib.rcParams['savefig.dpi']
935935
DEBUG_MSG("print_figure()", 1, self)
936936
# Save state information, and set save DPI
937937

0 commit comments

Comments
 (0)