I'm trying to create an image using matplotlib.pyplot.imshow()
. However, when I run the program from my console, it doesn't display anything?
This is the code:
import matplotlib.pyplot
myimage = gen_image()
matplotlib.pyplot.gray()
matplotlib.pyplot.imshow(results)
But this shows nothing.
The best use of Matplotlib differs depending on how you are using it; roughly, the three applicable contexts are using Matplotlib in a script, in an IPython terminal, or in an IPython notebook.
It means if we are not using the show() function, it wouldn't show any plot. When we use the show() function in the non-interactive mode. That means when we write the code in the file it will show all the figures or plots and blocks until the plots have been closed.
You have to call the show
function to actually display anything, like
matplotlib.pyplot.show()
Unfortunately the matplotlib documentation seems to be currently broken, so I can't provide a link.
Note that for interactive plotting one typically uses IPython, which has special support for matplotlib.
By the way, you can do
import matplotlib.pyplot as plt
to make the typing less tedious (this is pretty much the official standard way).
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