I recently installed Anaconda distribution (with sudo
, under /usr/lib
).
However, when trying to execute the following lines:
from matplotlib import pyplot
from numpy import zeros
pyplot.imshow(zeros((100, 100)))
Nothing happens (I expect to see a black screen). No error at all.
What am I missing?
imshow always displays an image in the current figure. If you display two images in succession, the second image replaces the first image. To view multiple figures with imshow , use the figure command to explicitly create a new empty figure before calling imshow for the next image.
By default, imshow normalizes the data to its min and max. You can control this with either the vmin and vmax arguments or with the norm argument (if you want a non-linear scaling).
The matplotlib function imshow() creates an image from a 2-dimensional numpy array. The image will have one square for each element of the array. The color of each square is determined by the value of the corresponding array element and the color map used by imshow() .
You need to tell matplotlib to show
the plot (or save the figure to a file) after making it.
To display the plot on the screen, try adding pyplot.show()
after your imshow
line.
To save to a file, try pyplot.savefig('myfig.png')
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