Matplotlib 导航工具栏:删除 "Edit curves lines and axes parameters"

Matplotlib Navigation Toolbar: remove "Edit curves lines and axes parameters"

最近我开始探索在 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?

除了最后一个按钮外,它对每个按钮都适用,带有描述 "Edit curves line and axes parameters" 的复选框绘图。 在这种特殊情况下,我真的很想删除这个按钮,因为它会在移动鼠标时不断调整绘图的大小,在这种情况下我不需要这个按钮。

我还没有找到任何讨论这个特定工具栏按钮的线程(只有这个 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')]

这成功嵌入了工具栏,但 "edit" 按钮仍然存在。

非常感谢您的任何见解。 此致

您可以通过将以下内容添加到您的 NavigationToolbar class

来删除它
    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')