Reputation: 43
I ran into a problem whilst trying to save a 920px width png from numpy data. One column is missing. It seems only this width causes the problem (I tried some others and the problem did not happen). MWE:
import matplotlib.pyplot as plt
import numpy as np
a1 = np.zeros((919, 100))
a2 = np.zeros((920, 100))
a3 = np.zeros((921, 100))
plt.imsave('test1.png', a1)
plt.imsave('test2.png', a2)
plt.imsave('test3.png', a3)
The resulting images all have a height of 100, but the widths are:
What is happening here?
Versions:
Upvotes: 4
Views: 75
Reputation: 114946
It is a matplotlib bug: https://github.com/matplotlib/matplotlib/issues/4280. Apparently it was fixed in February 2016 (maybe in https://github.com/matplotlib/matplotlib/pull/5718), but I don't think there has been a release since the bug was fixed in the master branch.
A work-around is to use the argument dpi=1
in the imsave
function, e.g.:
plt.imsave("foo.png", a, dpi=1)
but a DPI of 1 might confuse some software that reads the PNG file.
Upvotes: 2