plt.show() 使终端挂起 [英] plt.show() making terminal hang
问题描述
在我的一个程序中调用的最后一个函数的末尾,我具有以下代码来绘制简单的颜色图.
At the end of the last function I call in one of my programs, I have the following code to plot a simple color plot.
plt.figure()
plt.pcolormesh(X,Y,Z)
plt.colorbar()
plt.show()
事后我回到主程序,我的程序完成了.该图将按预期显示,但是当我使用角落中的x按钮(在ubuntu上)关闭它时,我的程序并没有结束.它只是挂着一个正在运行的进程.我该如何纠正?
Afterwords I return to main and my program is complete. The plot displays as expected, however when I go to close it using the x button in the corner (on ubuntu), my program doesn't end. It just hangs there with a process running. How can I correct this?
推荐答案
您的 matplotlib 可能在 非互动模式由于某种原因.我不确定如何在本地配置中防止这种情况,但是如果您添加以下任一方法:
your matplotlib might be running in non-interactive mode for some reason. I am not sure how to prevent that in your local configuration but if you add either this:
plt.ion()
或者这个:
matplotlib.interactive(True)
在脚本开始的某个位置,它应该更改绘图的行为.
somewhere at the beginning of your script, it should change the behaviour of your plots.
这篇关于plt.show() 使终端挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!