1 thought on “imsave reduces 1row from the image

  1. Got trapped by the same bug. For anybody looking for a quick solution, a way around this is to set dpi=1:

    In [16]: plt.imsave('foo.png', np.random.rand(115,100))
    In [17]: Image.open('foo.png').size[::-1]
    Out[17]: (114, 100)
    In [18]: plt.imsave('foo.png', np.random.rand(115,100), dpi=1)
    In [19]: Image.open('foo.png').size[::-1]
    Out[19]: (115, 100)
    

    Note that PNGs of dpi=1 will not play well with pdflatex. That’s why the dpi setting was introduced in the first place, but possibly not carefully enough. A way around that is to either set the dpi to the greatest common divisor of height and width, or, if that is still too small, strip the dpi from the resulting PNG afterwards.

Comments are closed.