python - Matplotlib 导航工具栏 : remove "Edit curves lines and axes parameters"

标签 python matplotlib plot pyqt toolbar

最近我开始探索在 Qt Designer 中开发 UI 并通过 PyQt 编辑它们。 事情一直很顺利,但我目前无法解决以下问题:

我已经通过 Qt Designer 插入了一个 MatplotLib 小部件,并设法使用 barh 绘制了非常好的水平条。接下来我尝试并成功地设法通过 matplotlib.backends.backend_qt4agg.NavigationToolbar2QT 插入一个功能性的 NavigationToolBar

然后,在这个线程(和类似线程)之后,我设法编辑了我想在工具栏上显示的按钮... How to modify the navigation toolbar easily in a matplotlib figure window?

它适用于除最后一个按钮外的每个按钮,带有一个描述“编辑曲线和轴参数”的复选框图。 在这种特殊情况下,我真的很想删除此按钮,因为它会在移动鼠标时不断调整绘图的大小,在这种情况下我不需要此按钮。

我还没有找到任何讨论这个特定工具栏按钮的线程(只有这个 matplotlib: Qt4Agg toolbar's irritating bug)

用于插入工具栏和当前编辑按钮的代码如下所示:

from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT

class currentUI(QtGui.QWidget):

    def __init__(self):
        super(currentUI,self).__init__()
        (...)
        uic.loadUi('portfolioManager.ui',self)
        self.initUI()
        (...)
    def initUI(self):        
        self.setWidgetsPropertiesAndActions()
    (...)
    def setWidgetsPropertiesAndActions(self):
        (...)
        self.navi_toolbar=NavigationToolbar(self.mplwidgetExposures, self)
        self.LayoutPlot.addWidget(self.navi_toolbar)
(...)
class NavigationToolbar(NavigationToolbar2QT):

    toolitems = [t for t in NavigationToolbar2QT.toolitems if
                 t[0] in ('Home','Pan', 'Zoom', 'Save','Subplots')]

这成功嵌入了工具栏,但“编辑”按钮仍然存在。

非常感谢任何见解。 问候

最佳答案

您可以通过将以下内容添加到您的 NavigationToolbar 类中来删除它

    actions = self.findChildren(QtGui.QAction)
    for a in actions:
        if a.text() == 'Customize':
            self.removeAction(a)
            break

无法通过修改 toolitems 删除此特定按钮的原因是,在添加所有 toolitems 条目后,它会单独添加到工具栏。

    for text, tooltip_text, image_file, callback in self.toolitems:
        if text is None:
            self.addSeparator()
        else:
            a = self.addAction(self._icon(image_file + '.png'),
                                     text, getattr(self, callback))
            self._actions[callback] = a
            if callback in ['zoom', 'pan']:
                a.setCheckable(True)
            if tooltip_text is not None:
                a.setToolTip(tooltip_text)

    if figureoptions is not None:
        a = self.addAction(self._icon("qt4_editor_options.png"),
                           'Customize', self.edit_parameters)
        a.setToolTip('Edit curves line and axes parameters')

关于python - Matplotlib 导航工具栏 : remove "Edit curves lines and axes parameters",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32869888/

相关文章:

r - 自动将 wordcloud2 导出为 html?

python - 调用 plt.show() 后如何保持之前的图而不清除图形而不简单地重复调用?

r - 为绘图添加额外的图例

python - beautifulSoup html csv

python - 将 python 脚本及其生成的进程的输出通过管道传输到 Linux 中的文本文件

python - 绘制离散变量的 CDF - 使用交替线的步骤图

python - 如何用 pandas 和 matplotlib 绘制两个分类(名义)系列之间的比较

r - 在R中绘制多个图时更改图的大小

Python + CGI脚本无法访问环境变量

python - 如何迭代两个不同大小的列表以获得新列表?