简体   繁体   English

matplotlib:Qt4Agg工具栏的令人讨厌的错误

[英]matplotlib: Qt4Agg toolbar's irritating bug

I am using the Qt4Agg (PyQt4) as the backend for rendering plots in matplotlib. 我正在使用Qt4Agg(PyQt4)作为在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). (我知道它很有用,因为它适用于条形图,但不适用于折线图:P)。

The cause and traceback can be seen clearly in the picture below. 下图可以清楚地看出原因和追溯。

在此处输入图片说明

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. 我认为这可能是matplotlib当前版本的错误,所以我在最新版本的matplotlib上尝试了此错误,但仍然出现相同的错误。

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()

(I have configured the backend through the configuration file /etc/matplotlibrc ) (我已经通过配置文件/etc/matplotlibrc配置了后端)

Please help me fix this problem. 请帮助我解决此问题。

This does indeed seem to be a bug in the Qt4 form editor for matplotlib. 这确实确实是matplotlib的Qt4表单编辑器中的错误。

The error appears to be within a section of the FormWidget.setup() method, in matplotlib/backends/qt4_editor/formwidget.py . 错误似乎在FormWidget.setup()方法的一部分中,位于matplotlib/backends/qt4_editor/formwidget.py In matplotlib 1.1.0 on Windows (where I couldn't reproduce the problem), it contains the following: 在Windows上的matplotlib 1.1.0(我无法重现该问题)中,它包含以下内容:

        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)

matplotlib v1.1.1rc on Kubuntu Precise (where I could reproduce the problem) replaces the second line of the above with Kubuntu Precise上的matplotlib v1.1.1rc(我可以重现该问题)用替换了上面的第二行

            selindex = list(value).pop(0)

Ultimately, neither version is correct. 最终,这两个版本都不正确。

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.0版方法的问题在于它不处理元组(元组是不可变的,并且没有pop )方法,而1.1.1rc版代码的问题在于,假定value的第一个元素要删除,但只会从list(value)创建的临时列表中删除。

This bug is fixed in version 1.1.1. 此错误已在1.1.1版中修复。 I've just downloaded and installed this version and can no longer reproduce the problem. 我刚刚下载并安装了此版本,无法再出现此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM