当要求绘制第二个图表时,Python Matplotlib挂起(关闭第一个图表窗口后) [英] Python Matplotlib hangs when asked to plot a second chart (after closing first chart window)

查看:46
本文介绍了当要求绘制第二个图表时,Python Matplotlib挂起(关闭第一个图表窗口后)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

奇怪的行为,我确定是我搞砸了,但我想了解正在发生的事情:

Weird behaviour, I'm sure it's me screwing up, but I'd like to get to the bottom of what's happening:

我正在运行以下代码,以使用matplotlib创建一个非常简单的图形窗口:

I am running the following code to create a very simple graph window using matplotlib:

>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> ax.plot((1, 3, 1))
[<matplotlib.lines.Line2D object at 0x0290B750>]
>>> plt.show()

并且如预期的那样,在弹出的新窗口中,我得到了一个图表,它包含一个非常简单的蓝线,它在y轴上从1到3再回到1,以0、1、2作为x轴点(仅作为示例).现在我关闭图形窗口(使用窗口右上方的十字按钮).这让我可以控制解释器,然后我重新开始,创建新对象:

and as expected I get the chart one would expect, in a new window that has popped up, containing a very simple blue line going from 1 to 3 back to 1 again on y axis, with 0, 1, 2 as the x axis points (just as example). Now I close the graph window (using cross button in the top right under windows). This gives me control to the interpreter, and I start again, creating new objects:

>>>
>>> fig1 = plt.figure()
>>> bx = fig1.add_subplot(111)
>>> bx.plot((1, 3, 1))
[<matplotlib.lines.Line2D object at 0x029E8210>]
>>> plt.show()

这一次,我得到了一个窗框,里面没有任何东西(只是框架,没有白色背景也没有),整个爆炸都挂了.我必须结束任务",python 解释器被系统终止,我得到一个命令提示符.Mac 上的类似行为(除了它确实先绘制图形,然后再挂起).

This time though, I get a window frame, with nothing in it (just the frame, no white background nothing), and the whole bang shoot hangs. I have to "end task", the python interpreter is terminated by the system and I get a command prompt back. Similar behaviour on a mac (except it does actually plot the graph first, before also hanging).

所以不知何故 Python 和/或 matplotlib 不希望我手动关闭窗口.有人知道发生了什么以及我应该做什么吗?我想做的是在解释器中处理不同的情节,显然,这种行为无济于事.我知道我可以使用Ipython -pylab",但为了学习,我想了解上述错误.

So somehow Python and/or matplotlib doesn't want me to close the window manually. Anybody know what's going on and what I should be doing? What I'd like to do is play around with different plots from within the interpreter, and obviously this behaviour doesn't help. I know I could use "Ipython -pylab" but in the interests of learning, I want to understand the above error.

谢谢.

推荐答案

显然,这是由 tkinter 后端中的错误引起的.参见例如 https://bugs.launchpad.net/ubuntu/+source/matplotlib/+bug/313834 .正在处理中...如果您可以回归到稍微旧的 tkinter 库,那应该是暂时的解决方法(几周前我遇到了同样的事情,这是我唯一的希望).

Apparently, this is caused by a bug in the tkinter backend. See, e.g., https://bugs.launchpad.net/ubuntu/+source/matplotlib/+bug/313834 . It's being worked on... If you can regress to a slightly older tkinter library, that should be a workaround for the time-being (I ran into this same thing a couple of weeks ago, and that was my only hope).

这篇关于当要求绘制第二个图表时,Python Matplotlib挂起(关闭第一个图表窗口后)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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