I'm working on a program in python with packages numpy,scipy and matplotlib.pyplot. This is my code:
import matplotlib.pyplot as plt from scipy import misc im=misc.imread("photosAfterAverage/exampleAfterAverage1.jpg") plt.imshow(im, cmap=plt.cm.gray)
for some reason the image isn't showing up (checked if I got the image, in that part it's all fine- I can print the array.).
plt. imshow just finishes drawing a picture instead of printing it. If you want to print the picture, you just need to add plt. show .
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() .
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.
You need to call plt.show()
to display the image. Or use ipython --pylab
for an interactive shell that is matplotlib
aware.
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