以下代码
%matplotlib inline
for i in range(0, 5):
index = np.random.choice(len(dataset))
print('index:', index)
image = dataset[index, :, :]
print('image shape:', np.shape(image))
plt.imshow(image)
在jupyter notebook
结尾显示五个打印输出和一个图像。
是否可以在每次循环迭代中显示图像?
我可以用图像文件
for fullname in fullnames:
print('fullname:', fullname)
display(Image(filename=fullname))
对ndarrays也可以这样做吗?
更新
写作
for i in range(0, 5):
...
plt.figure()
plt.imshow(image)
使它更好,但不是完美的。图像显示为多个,但都在文本之后。
应该是交错的。
尝试:
如果没有
plt.show()
,图形只在单元格完成执行后呈现和显示(即退出for
循环)。使用plt.show()
可以在每次迭代后强制呈现。相关问题 更多 >
编程相关推荐