matplotlib:Qt4Agg 工具栏的恼人错误 [英] matplotlib: Qt4Agg toolbar's irritating bug

查看:46
本文介绍了matplotlib:Qt4Agg 工具栏的恼人错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Qt4Agg (PyQt4) 作为后端在 matplotlib 中渲染绘图.这有一个非常有用的工具栏和一个非常有用的按钮'编辑曲线和轴参数'.但是,每当我按下它时,它都会出错.(我知道它很有用,因为它适用于条形图,但不适用于线图:P).

I am using the Qt4Agg (PyQt4) as the backend for rendering plots in matplotlib. This has a very useful toolbar with a very useful button 'Edit curve lines and axes parameters'. However, whenever I press it, it gives an error. (I know that it is useful as it works for bar graphs, but not for line plots :P).

在下图中可以清楚地看到原因和追溯.

The cause and traceback can be seen clearly in the picture below.

我认为这可能是当前版本matplotlib的错误,因此我在最新版本的matplotlib上尝试了此操作,但仍然给出了相同的错误.

I thought this might be a bug the current version of matplotlib so I tried this on the latest version of the same but it still gives the same error.

这是给出相同错误的最简单脚本(情节与上面不同)-

This is simplest script which gives the same error (plot will be different from above) -

import matplotlib.pyplot as plt
plt.plot(range(10))
plt.show()

(我已经通过配置文件/etc/matplotlibrc配置了后端)

(I have configured the backend through the configuration file /etc/matplotlibrc)

请帮助我解决此问题.

推荐答案

这确实似乎是 matplotlib 的 Qt4 表单编辑器中的一个错误.

This does indeed seem to be a bug in the Qt4 form editor for matplotlib.

错误似乎出现在 matplotlib/backends/qt4_editor/formwidget.pyFormWidget.setup() 方法的一部分内.在 Windows 上的 matplotlib 1.1.0 中(我无法重现该问题),它包含以下内容:

The error appears to be within a section of the FormWidget.setup() method, in matplotlib/backends/qt4_editor/formwidget.py. In matplotlib 1.1.0 on Windows (where I couldn't reproduce the problem), it contains the following:

        elif isinstance(value, (list, tuple)):
            selindex = value.pop(0)
            field = QComboBox(self)
            if isinstance(value[0], (list, tuple)):
                keys = [ key for key, _val in value ]
                value = [ val for _key, val in value ]
            else:
                keys = value
            field.addItems(value)

Kubuntu Precise 上的 matplotlib v1.1.1rc(我可以在那里重现问题)用

matplotlib v1.1.1rc on Kubuntu Precise (where I could reproduce the problem) replaces the second line of the above with

            selindex = list(value).pop(0)

最终,两个版本都不正确.

Ultimately, neither version is correct.

1.1.0版方法的问题在于它不处理元组(元组是不可变的,并且没有 pop )方法,而版本1.1.1rc则存在问题code 是 value 的第一个元素应该被删除,但它只会从 list(value) 创建的临时列表中删除.

The problem with the version 1.1.0 method is that it doesn't handle tuples (tuples are immutable and don't have a pop) method, and the problem with the version 1.1.1rc code is that the first element of value is supposed to be removed, but it only gets removed from the temporary list that list(value) creates.

此错误已在1.1.1版中修复.我刚刚下载并安装了此版本,无法再出现此问题.

This bug is fixed in version 1.1.1. I've just downloaded and installed this version and can no longer reproduce the problem.

这篇关于matplotlib:Qt4Agg 工具栏的恼人错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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