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

Skip to content

Commit 35a9413

Browse files
committed
Support get_image_magnification in pdf backend
svn path=/trunk/matplotlib/; revision=3736
1 parent 2a29e4f commit 35a9413

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

lib/matplotlib/backends/backend_pdf.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ def writeTrailer(self):
10211021

10221022
class RendererPdf(RendererBase):
10231023

1024-
def __init__(self, file):
1024+
def __init__(self, file, dpi):
10251025
RendererBase.__init__(self)
10261026
self.file = file
10271027
self.gc = self.new_gc()
@@ -1033,6 +1033,7 @@ def __init__(self, file):
10331033
else:
10341034
self.encode_string = self.encode_string_type42
10351035
self.mathtext_parser = MathTextParser("Pdf")
1036+
self.image_magnification = dpi/72.0
10361037

10371038
def finalize(self):
10381039
self.gc.finalize()
@@ -1120,6 +1121,9 @@ def arc_to_bezier(cx, cy, rx, ry, angle1, sweep, rotation):
11201121

11211122
self.file.output(self.gc.close_and_paint())
11221123

1124+
def get_image_magnification(self):
1125+
return self.image_magnification
1126+
11231127
def draw_image(self, x, y, im, bbox):
11241128
#print >>sys.stderr, "draw_image called"
11251129

@@ -1128,6 +1132,7 @@ def draw_image(self, x, y, im, bbox):
11281132
self.check_gc(gc)
11291133

11301134
h, w = im.get_size_out()
1135+
h, w = h/self.image_magnification, w/self.image_magnification
11311136
imob = self.file.imageObject(im)
11321137
self.file.output(Op.gsave, w, 0, 0, h, x, y, Op.concat_matrix,
11331138
imob, Op.use_xobject, Op.grestore)
@@ -1735,7 +1740,7 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
17351740
filename += '.pdf'
17361741

17371742
file = PdfFile(width, height, filename)
1738-
renderer = RendererPdf(file)
1743+
renderer = RendererPdf(file, dpi)
17391744
self.figure.draw(renderer)
17401745
renderer.finalize()
17411746
file.close()

0 commit comments

Comments
 (0)