Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animation quality is better with matshow() than with imshow(). How to improve it?

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)

FIG 1

Imshow:

plt.imshow(array)

FIG 2

like image 951
Loïc Poncin Avatar asked Jan 28 '17 12:01

Loïc Poncin


1 Answers

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")
like image 160
ImportanceOfBeingErnest Avatar answered Nov 08 '22 22:11

ImportanceOfBeingErnest