Matplotlib/Tkinter 错误:比较 collection3d 对象时出现异常 [英] Matplotlib/Tkinter bug: exception when comparing collection3d objects

查看:21
本文介绍了Matplotlib/Tkinter 错误:比较 collection3d 对象时出现异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一个由 Matplotlib 窗口的 Tkinter 回调引发的奇怪异常.上下文:我在 QTconsole IPython 窗口中以 pylab 模式运行 Python 3.2.我正在编码的问题涉及三角形区域的 3D 绘图.

I'm getting a strange exception raised by a Matplotlib window's Tkinter callback. Context: I'm running Python 3.2 in a QTconsole IPython window, in pylab mode. The problem I'm coding involves 3D plotting over triangular regions.

(如果代码片段太长,我深表歉意;我发现该错误难以重现.)

(I apologize if the code snippet is rather long; I found the bug difficult to reproduce.)

from mpl_toolkits.mplot3d import Axes3D
A,B,C,D = array([[0,0],[1,0],[1/2,1],[3/2,1]])
f1 = lambda x,y: NaN if x==y==0 else (y - 2*x)*sin(1/(x**2+y**2))
f2 = lambda x,y: NaN if x==y==0 else (y-2*x+2)*cos(1/(x**2+y**2))
(U,V) = meshgrid(linspace(0,1),linspace(0,1))

fig = figure(1)
ax = fig.add_subplot(111,projection = '3d')

(X1,Y1) = vectorize(lambda u,v: tuple(A + u*(B-A) + u*v*(C-B)), otypes = [float,float])(U,V)
(X2,Y2) = vectorize(lambda u,v: tuple(D + u*(C-D) + u*v*(B-C)), otypes = [float,float])(U,V)
Z11 = vectorize(f1)(X1,Y1)
Z21 = vectorize(f2)(X1,Y1)
Z12 = vectorize(f1)(X2,Y2)
Z22 = vectorize(f2)(X2,Y2)

ax.plot_wireframe(X1,Y1,Z11)
ax.plot_wireframe(X1,Y1,Z21)
ax.plot_wireframe(X2,Y2,Z12)
ax.plot_wireframe(X2,Y2,Z22)
show()

绘制完所有这些补丁后,在图形窗口中单击鼠标会生成以下内容:

Once all these patches are drawn, a mouse-click in the figure window produces the following:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python32\lib\tkinter\__init__.py", line 1399, in __call__
    return self.func(*args)
[snip]
  File "C:\Python32\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 191, in draw
    zlist.sort()
TypeError: unorderable types: Line3DCollection() < Line3DCollection()
Exception in Tkinter callback

由于这是 Tkinter 引发的异常,我无法在 PDB 中捕获它并对其进行分析.(特别是,有很多未命名的参数传递给堆栈跟踪中的中间方法,因此无法手动跟踪它.)我已经能够弄清楚,实际上,Axes3D 实例正在尝试排序它的 Line3DCollection 对象列表,并针对未实现的比较方法运行.

Since this is a Tkinter-raised exception, I can't catch it in PDB and analyze it. (In particular, there are a lot of unnamed arguments passed to the intermediate methods in the stack trace that make it impossible to follow it down by hand.) I have been able to figure out that, indeed, the Axes3D instance is trying to sort its list of Line3DCollection objects and running up against an un-implemented comparison method.

我的问题是:这是 Matplotlib 需要注意的错误,还是我犯了某种基本的用户错误?(如前所述,这个错误很挑剔;它并不总是出现,尤其是当我以不同的方式参数化三角形时.)

My question is: is this a bug that Matplotlib needs to be made aware of, or am I making some kind of basic user mistake? (As mentioned, the bug is finicky; it doesn't always show up, especially if I parametrize the triangles in different ways.)

推荐答案

通过更新 mpl 1.2.1 修复了问题(如对 OP 的评论中所报告).

Issue fixed by updating mpl 1.2.1 (as reported in comments to OP).

这篇关于Matplotlib/Tkinter 错误:比较 collection3d 对象时出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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