The function pyplot.imshow
only writes the image to the buffer that will be shown/stored/etc in subsequent actions (this is how you can use pyplot.title
, pyplot.xlim
, and other commands in a sequence and then only have one plot at the end of all of them).
The reason it seems to display an image in Jupyter is because it's the last line of code executed in the cell, and Jupyter always tries to render the last item it sees unless that behavior is disabled (note that pyplot.imshow
actually returns an image object which could be rendered -- Jupyter has logic in place which attempts to do so).
If you really just want to display those items in a loop (as opposed to using subplots or some other way to construct a composite image) then you need to add an additional pyplot.show()
command:
from matplotlib import pyplot
file_names = ['a', 'b', 'c']
for name in file_names:
image = cv2.imread(name)
pyplot.imshow(image)
pyplot.show()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…