plt.show() 使终端挂起 [英] plt.show() making terminal hang

查看:55
本文介绍了plt.show() 使终端挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一个程序中调用的最后一个函数的末尾,我具有以下代码来绘制简单的颜色图.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆