Skip to content

Commit 814662a

Browse files
committed
Fix vertical image bounds when on an half display pixel
The Agg renderer internally has the vertical axis flipped, so the rounding of the bounds in the vertical direction needs to be round half down instead of round half up.
1 parent 38d9ed5 commit 814662a

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

lib/matplotlib/image.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,9 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
408408
magnified_extents = clipped_bbox.extents * magnification
409409
if ((not unsampled) and round_to_pixel_border):
410410
# Round to the nearest output pixel
411-
magnified_bbox = Bbox.from_extents((magnified_extents + 0.5).astype(int))
411+
x0, x1 = np.floor(magnified_extents[0::2] + 0.5) # round half up
412+
y0, y1 = np.ceil(magnified_extents[1::2] - 0.5) # round half down
413+
magnified_bbox = Bbox.from_extents([x0, y0, x1, y1])
412414
else:
413415
magnified_bbox = Bbox.from_extents(magnified_extents)
414416

0 commit comments

Comments
 (0)