Skip to content

Commit

Permalink
Fix matplotlib#5520: Don't round up if already rounded
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Feb 9, 2016
1 parent 6febf00 commit a053d15
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/matplotlib/image.py
Expand Up @@ -273,7 +273,9 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
# to round up the output width to the next integer. This also
# means scaling the transform just slightly to account for the
# extra subpixel.
if t.is_affine and round_to_pixel_border:
if (t.is_affine and round_to_pixel_border and
(out_width_base % 1.0 != 0.0 or
out_height_base % 1.0 != 0.0)):
out_width = int(ceil(out_width_base) + 1)
out_height = int(ceil(out_height_base) + 1)
extra_width = (out_width - out_width_base) / out_width_base
Expand Down
23 changes: 23 additions & 0 deletions lib/matplotlib/tests/test_image.py
Expand Up @@ -580,6 +580,29 @@ def test_rotate_image():
ax1.set_ylim(0, 4)


@cleanup
def test_image_preserve_size2():
n = 7
data = np.identity(n, float)

fig = plt.figure(figsize=(n, n), frameon=False)

ax = plt.Axes(fig, [0.0, 0.0, 1.0, 1.0])
ax.set_axis_off()
fig.add_axes(ax)
ax.imshow(data, interpolation='nearest', origin='lower',aspect='auto')
buff = io.BytesIO()
fig.savefig(buff, dpi=1)

buff.seek(0)
img = plt.imread(buff)

assert img.shape == (7, 7, 4)

assert_array_equal(np.asarray(img[:, :, 0], bool),
np.identity(n, bool)[::-1])


if __name__=='__main__':
import nose
nose.runmodule(argv=['-s','--with-doctest'], exit=False)

0 comments on commit a053d15

Please sign in to comment.