[PyQt] pyqt-plot

Darren Dale dsdale24 at gmail.com
Sun Feb 27 12:49:42 GMT 2011


On Sun, Feb 27, 2011 at 5:43 AM, nimi pillai <nimi.snowhills at gmail.com> wrote:
> Hi all,
>
> I am totally new to python programming and especially pyqt..
>  I tried to use plot in a small GUI application which should produce a new
> figure window when we click the push button.
> It works well in Windows. In Ubuntu the plot window appears only once ;ie
> first click. But the 'print' statements are appearing.Also the Gui window
> becomes active only if we close the figure window.
>
> from pylab import *
> import matplotlib.pyplot as plt
> import sys
> from PyQt4 import QtCore, QtGui
> from push import Ui_Form
>
> class Form(QtGui.QMainWindow):
>
>   def __init__(self, parent=None):
>     QtGui.QWidget.__init__(self, parent)
>     self.ui = Ui_Form()
>     self.ui.setupUi(self)
>     QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"),
> self.toplot)
>
>   def toplot(self):
>       x=[1,2,3]
>       y=[1,2,3]
>       figure(1)
>       plot(x,y)
>       show()
>       print x
>       print y
>
>
> if __name__ == "__main__":
>   app = QtGui.QApplication(sys.argv)
>   a = Form()
>   a.show()
>   sys.exit(app.exec_())
>
>
> Thanks in advance.

The pyplot/pylab APIs are intended for scripting and interactive use,
like in ipython. They are not meant for integration with a gui
application running its own event loop. See
http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_qt4.html
for an example of how to use matplotlib in a PyQt4 applitcation.

Darren


More information about the PyQt mailing list