How do I convert a numpy array to (and display) an image?

The following should work:

from matplotlib import pyplot as plt
plt.imshow(data, interpolation='nearest')
plt.show()

If you are using Jupyter notebook/lab, use this inline command before importing matplotlib:

%matplotlib inline 

A more featureful way is to install ipyml pip install ipympl and use

%matplotlib widget 

see an example.

Leave a Comment