How to embed a plot directly into a Window (python; QT;) -
i wanna embed matplotlib plot directly window, qmainwindow. should part of program more complex gui. ;)
the way found add figure widget qtabwidget. see sample code below. lost link webpage inspired me.
is there way embed figure directly windows other elements (buttons, textfield, textarea, ...)?
import sys pyqt4.qtgui import qapplication, qmainwindow, qdockwidget, qvboxlayout,qtabwidget, qwidget matplotlib import pyplot matplotlib.backends.backend_qt4agg import figurecanvasqtagg = qapplication(sys.argv) w = qmainwindow() t = qtabwidget(w) tab1 = qwidget() t.addtab(tab1, '1st plot') t.resize(1280, 300) x = [1, 2, 3] fig1 = pyplot.figure(); plot = fig1.add_subplot(111); plot.plot(x) plot.grid(); layout = qvboxlayout(); layout.addwidget(figurecanvasqtagg(fig1)); tab1.setlayout(layout); w.showmaximized() sys.exit(a.exec_()) thank much.
figurecanvasqtagg qwidget of other controls mentioned. main difference being doesn't allow pass parent in constructor when write
t = qtabwidget(w) you can achieve same figurecanvasqtagg calling setparent
canvas = figurecanvasqtagg(fig1) canvas.setparent(w) you can use qmainwindow's setcentralwidget method add matplotlib figurecanvas directly main window. however, if want more complex gui other controls don't see real problems current approach.
lastly, shouldn't using pyplot when embedding matplotlib. stick object oriented api. take @ this example.
Comments
Post a Comment