我想使用imshow()
和for
循环显示一系列图像,但我想在继续之前等待图像上的用户输入(不在终端上)。以下确实有效但它需要关闭窗口,这不是最佳的,因为我的for循环有超过一千次迭代。如何将plt.clf()暂时解除阻塞直到下一个循环。
x, y, z = sp.mgrid[0:10, 0:100, 0:100]
for img in x:
f = plt.figure()
def onkey(event):
print("pressed {}".format(event))
plt.close(f)
f.canvas.mpl_connect("key_press_event", onkey)
plt.imshow(img)
plt.show()
print("continuing")
谢谢!
答案 0 :(得分:0)
使用:
plt.ion()
plt.show()
循环前,然后删除plt.close()
&循环中plt.show()
。
要阻止循环直到发生按下事件,请添加:
f.canvas.start_event_loop(timeout=-1)
循环内的