matplotlib: Qt4Agg toolbar's irritating bug

泄露秘密 提交于 2019-12-11 09:18:02

问题


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.

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

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

Please help me fix this problem.


回答1:


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

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)

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.

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.

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



来源:https://stackoverflow.com/questions/12445732/matplotlib-qt4agg-toolbars-irritating-bug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!