I displayed an array with matshow and it works fine but now I want to try imshow. The issue is that the quality of imshow is really poor compared to matshow.
How can I fix this ?
Matshow:
matshow(array)
Imshow:
plt.imshow(array)
The issue is due to interpolation.
Matplotlib matshow
is a wrapper for imshow
, in that it "sets origin to ‘upper’, ‘interpolation’ to ‘nearest’ and ‘aspect’ to equal."
So while matshow always uses interpolation="nearest"
, imshow
by default has interpolation=None
. Note that this is different from interpolation="none"
.
interpolation=None
uses the interpolation set in the image.interpolation
variable from the matplotlib rc file (which can be different in different matplotlib versions.) interpolation="none"
uses no interpolation, same as "nearest"
The safest way to overcome this problem is to specifically set an interpolation method in both calls
plt.matshow(array, interpolation="none")
plt.imshow(array, interpolation="none")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With