If I call plt.show() prior to calling
plt.imshow(i), then an error results.
If I call plt.imshow(i) prior to
calling plt.show(), then everything
works perfectly.
plt.show()
displays the figure (and enters the main loop of whatever gui backend you're using). You shouldn't call it until you've plotted things and want to see them displayed.
plt.imshow()
draws an image on the current figure (creating a figure if there isn't a current figure). Calling plt.show()
before you've drawn anything doesn't make any sense. If you want to explictly create a new figure, use plt.figure()
.
... a new figure is displayed without ever
calling plt.show().
That wouldn't happen unless you're running the code in something similar to ipython's pylab mode, where the gui backend's main loop will be run in a separate thread...
Generally speaking, plt.show() will be the last line of your script. (Or will be called whenever you want to stop and visualize the plot you've made, at any rate.)
Hopefully that makes some more sense.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…