Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Recently I began exploring developing UI in Qt Designer and editing them through PyQt. Things have been going pretty smoothy, but I'm currently stuck trying to solve the following issue:

I've inserted a MatplotLib widget through Qt Designer and managed to plot pretty well horizontal bars using barh. Next I tried and successfully managed to insert a functional NavigationToolBar through matplotlib.backends.backend_qt4agg.NavigationToolbar2QT

Then, following this thread (and similar ones) I managed to edit which buttons I would like to display on the toolbar... How to modify the navigation toolbar easily in a matplotlib figure window?

It works well for every button except for the last one, with a check box drawing which description "Edit curves line and axes parameters". In this particular case, I would really like to remove this button, because it constantly resizes the plot when moving the mouse and in this case I don't need this button.

I haven't found yet any thread discussing this particular toolbar button (just this one matplotlib: Qt4Agg toolbar's irritating bug)

The code used to insert the toolbar and currently edit buttons looks something like this:

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')]

This successfully embeds the toolbar, but the "edit" button remains.

Thanks very much for any insight. Regards

like image 810
Mauro Villalon Avatar asked Sep 30 '15 15:09

Mauro Villalon


1 Answers

You can remove it by adding the following to your NavigationToolbar class

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

The reason you can't remove this particular button by modifying toolitems is because it gets added to the toolbar separately after all the toolitems entries have been added.

    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')
like image 105
user3419537 Avatar answered Sep 29 '22 17:09

user3419537