Adding a toolbar to an MPL metric in PyQt4

I have a very simple pyqt4 application that has a MatPlotLib figure embedded. I embed a matplotlib figure through MatplotlibWidget, and I created the interface through QtDesigner along with pyuic4 .

I would like to give the user access to the toolbar for interactive navigation . But despite their good GTK example, I can't get it to work on pyQt. It mentions examples, but the example for QT4 provided does not include a toolbar.

I appreciate any help with this.


This question is similar, but not quite suitable for what I need, and I could not adapt it.

+3
source share
1

QtDesigner , :

, plot_layout - QVBoxLayout, QtDesigner, plot_canvas - MatplotlibWidget.

import numpy as np
from PyQt4.QtCore import Qt
from PyQt4.QtGui import *
from matplotlib.backends.backend_qt4 import NavigationToolbar2QT as NavigationToolbar
from plot_dialog2 import Ui_Form

class PlotDialog(QWidget, Ui_Form):
    def __init__(self):
        QWidget.__init__(self)
        self.setupUi(self)
        self.navi_toolbar = NavigationToolbar(self.plot_canvas, self)
        self.plot_layout.addWidget(self.navi_toolbar)

if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)
    dialog = PlotDialog()
    dialog.show()
    sys.exit(app.exec_())
+5

All Articles