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

Skip to content

Commit 9448208

Browse files
committed
Fix #5520: Don't round up if already rounded
1 parent 4c5a3bf commit 9448208

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/matplotlib/image.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
273273
# to round up the output width to the next integer. This also
274274
# means scaling the transform just slightly to account for the
275275
# extra subpixel.
276-
if t.is_affine and round_to_pixel_border:
276+
if (t.is_affine and round_to_pixel_border and
277+
(out_width_base % 1.0 != 0.0 or
278+
out_height_base % 1.0 != 0.0)):
277279
out_width = int(ceil(out_width_base) + 1)
278280
out_height = int(ceil(out_height_base) + 1)
279281
extra_width = (out_width - out_width_base) / out_width_base

lib/matplotlib/tests/test_image.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,29 @@ def test_rotate_image():
580580
ax1.set_ylim(0, 4)
581581

582582

583+
@cleanup
584+
def test_image_preserve_size2():
585+
n = 7
586+
data = np.identity(n, float)
587+
588+
fig = plt.figure(figsize=(n, n), frameon=False)
589+
590+
ax = plt.Axes(fig, [0.0, 0.0, 1.0, 1.0])
591+
ax.set_axis_off()
592+
fig.add_axes(ax)
593+
ax.imshow(data, interpolation='nearest', origin='lower',aspect='auto')
594+
buff = io.BytesIO()
595+
fig.savefig(buff, dpi=1)
596+
597+
buff.seek(0)
598+
img = plt.imread(buff)
599+
600+
assert img.shape == (7, 7, 4)
601+
602+
assert_array_equal(np.asarray(img[:, :, 0], bool),
603+
np.identity(n, bool)[::-1])
604+
605+
583606
if __name__=='__main__':
584607
import nose
585608
nose.runmodule(argv=['-s','--with-doctest'], exit=False)

0 commit comments

Comments
 (0)