If I call plt.show () before calling plt.imshow (i), an error occurs. If I call plt.imshow (i) before calling plt.show (), then everything works fine.
plt.show() displays the shape (and is included in the mainloop of any backend you use). You should not name it until you have things in mind and do not want them to be displayed.
plt.imshow() draws an image in the current figure (there is no current figure to create a figure). Calling plt.show() before you draw anything makes no sense. If you want to explicitly create a new shape, use plt.figure() .
... a new figure is displayed unbeknownst to plt.show ().
This will not happen if you do not use the code in something similar to the pythab ipython mode, where the mainloop gui backend will be launched in a separate thread ...
Generally speaking, plt.show () will be the last line of your script. (Or it will be called up whenever you want to stop and visualize the plot you made, anyway.)
Hope this makes sense.
Joe kington
source share