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

Skip to content

Commit d262778

Browse files
committed
Fix one-pixel space between images and axes border.
svn path=/trunk/matplotlib/; revision=5402
1 parent b1d3d91 commit d262778

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2008-06-05 Fix image drawing so there is no extra space to the right
2+
or bottom - MGD
3+
14
2006-06-04 Added a figure title command subtitle as a Figure method
25
and pyplot command -- see examples/figure_title.py - JDH
36

lib/matplotlib/image.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ def make_image(self, magnification=1.0):
205205
tx = (xmin-self.axes.viewLim.x0)/dxintv * numcols
206206
ty = (ymin-self.axes.viewLim.y0)/dyintv * numrows
207207

208-
l, b, widthDisplay, heightDisplay = self.axes.bbox.bounds
208+
l, b, r, t = self.axes.bbox.extents
209+
widthDisplay = (round(r) + 0.5) - (round(l) - 0.5)
210+
heightDisplay = (round(t) + 0.5) - (round(b) - 0.5)
209211
widthDisplay *= magnification
210212
heightDisplay *= magnification
211213
im.apply_translation(tx, ty)
@@ -226,7 +228,7 @@ def draw(self, renderer, *args, **kwargs):
226228
warnings.warn("Images are not supported on non-linear axes.")
227229
im = self.make_image(renderer.get_image_magnification())
228230
l, b, widthDisplay, heightDisplay = self.axes.bbox.bounds
229-
renderer.draw_image(l, b, im, self.axes.bbox.frozen(),
231+
renderer.draw_image(round(l), round(b), im, self.axes.bbox.frozen(),
230232
*self.get_transformed_clip_path_and_affine())
231233

232234
def contains(self, mouseevent):
@@ -378,7 +380,9 @@ def make_image(self, magnification=1.0):
378380
raise RuntimeError('You must first set the image array')
379381

380382
x0, y0, v_width, v_height = self.axes.viewLim.bounds
381-
l, b, width, height = self.axes.bbox.bounds
383+
l, b, r, t = self.axes.bbox.extents
384+
width = (round(r) + 0.5) - (round(l) - 0.5)
385+
height = (round(t) + 0.5) - (round(b) - 0.5)
382386
width *= magnification
383387
height *= magnification
384388
im = _image.pcolor(self._Ax, self._Ay, self._A,
@@ -487,8 +491,11 @@ def make_image(self, magnification=1.0):
487491
fc = self.axes.get_frame().get_facecolor()
488492
bg = mcolors.colorConverter.to_rgba(fc, 0)
489493
bg = (np.array(bg)*255).astype(np.uint8)
490-
width = self.axes.bbox.width * magnification
491-
height = self.axes.bbox.height * magnification
494+
l, b, r, t = self.axes.bbox.extents
495+
width = (round(r) + 0.5) - (round(l) - 0.5)
496+
height = (round(t) + 0.5) - (round(b) - 0.5)
497+
width = width * magnification
498+
height = height * magnification
492499
if self.check_update('array'):
493500
A = self.to_rgba(self._A, alpha=self._alpha, bytes=True)
494501
self._rgbacache = A
@@ -508,8 +515,8 @@ def make_image(self, magnification=1.0):
508515
def draw(self, renderer, *args, **kwargs):
509516
if not self.get_visible(): return
510517
im = self.make_image(renderer.get_image_magnification())
511-
renderer.draw_image(self.axes.bbox.xmin,
512-
self.axes.bbox.ymin,
518+
renderer.draw_image(round(self.axes.bbox.xmin),
519+
round(self.axes.bbox.ymin),
513520
im,
514521
self.axes.bbox.frozen(),
515522
*self.get_transformed_clip_path_and_affine())
@@ -638,7 +645,7 @@ def make_image(self, magnification=1.0):
638645
def draw(self, renderer, *args, **kwargs):
639646
if not self.get_visible(): return
640647
im = self.make_image()
641-
renderer.draw_image(self.ox, self.oy, im, self.figure.bbox,
648+
renderer.draw_image(round(self.ox), round(self.oy), im, self.figure.bbox,
642649
*self.get_transformed_clip_path_and_affine())
643650

644651
def write_png(self, fname):

0 commit comments

Comments
 (0)