关闭每次迭代中的matplotlib图
我有一个循环,需要在每次迭代中显示一个数字,我需要完全关闭图形,并在一段时间后显示另一个数字。这是我的代码:
for j in range (3):
img = mpimg.imread("E" + str(j) + ".jpg")
imgplot = plt.imshow(img)
plt.show(block=False)
plt.pause(3)
plt.close()
这里似乎每个数字都会用另一个数字替换,尽管我需要代码才能完全关闭第一个数字,进行一些操作然后显示另一个数字。 ),但它不起作用。
任何帮助将不胜感激。
I have a loop and need to show a figure in each iteration, I need to close the figure completely and after a while show another figure. This is my code:
for j in range (3):
img = mpimg.imread("E" + str(j) + ".jpg")
imgplot = plt.imshow(img)
plt.show(block=False)
plt.pause(3)
plt.close()
Here it seems that each figure will replace with another figure although I need the code to close the first figure completely, do some operations and then show another figure.I even used plt.close("all") but it didn't work.
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不明白您的确切期望,但是添加
plt.pause(1)
可以具有相似的结果。如果您的PLT后端是QT(您可以通过
plt.get_backend()
)进行检查,以进行数字的绝对定位,请使用plt.get_current_fig_manager()。 Y0,宽度,高度)
函数。此外,如果您希望某些操作控制开口和关闭数字,则插入
,而
带有键盘输入的循环可能是一个简单的灵魂。在此代码中,第一个数字posp上升了3秒,它将在1秒内关闭。然后第二个弹出。
I don't understand what you exactly expect, but adding
plt.pause(1)
can have a similar result.If your plt backend is Qt (you can check it via
plt.get_backend()
), for absolute positioning of the figures, please useplt.get_current_fig_manager().window.setGeometry(x0,y0,width,height)
function.Additionally, if you want some operations to control the opening and closing figures, inserting
while
loop with keyboard input can be a simple soultion.In this code, the first figure posp up for 3 seconds and it will close in 1 second. Then the second one pops up.