I am currently trying to embed a graph I want to plot in a pyqt4 user interface I designed. As I am almost completely new to programming – I do not get how people did the embedding in the examples I found – this one (at the bottom) and that one.
It would be awesome if anybody could post a step-by-step explanation or at least a very small, very simple code only creating e.g. a graph and a button in one pyqt4 GUI.
It is not that complicated actually. Relevant Qt widgets are in
matplotlib.backends.backend_qt4agg.FigureCanvasQTAggandNavigationToolbar2QTare usually what you need. These are regular Qt widgets. You treat them as any other widget. Below is a very simple example with aFigure,Navigationand a single button that draws some random data. I’ve added comments to explain things.Edit:
Updated to reflect comments and API changes.
NavigationToolbar2QTAggchanged withNavigationToolbar2QTFigureinstead ofpyplotax.hold(False)withax.clear()