There is definitely something weird going on here. It could still be a bad
command on my part, but I cannot get Windows to plot interactively if I embed
it in pyqt. I even tried adapting one of the qt examples from the matplotlib
homepage and I still have the same problem (i.e., it will only plot point by
point in Linux). I'm attaching two files to illustrate: (1) a simple program
that works interactively in both Windows and Linux without qt; and (2) the
example from the homepage with my code inserted (which is the same code that I
used in the first attachment that behaves properly). I'm wondering if there is
some issue with qt and Windows at work.
Any thoughts?
Thanks,
Steve
--- On Tue, 6/9/09, John Hunter <jdh2...@gmail.com> wrote:
From: John Hunter <jdh2...@gmail.com>
Subject: Re: [Matplotlib-users] MPL with PyQt: different behavior on Windows
vs. Linux
To: "Steve Nicholes" <emailaddress_...@yahoo.com>
Cc: matplotlib-users@lists.sourceforge.net
Date: Tuesday, June 9, 2009, 6:25 PM
On Tue, Jun 9, 2009 at 5:17 PM, Steve
Nicholes<emailaddress_...@yahoo.com> wrote:
> I am writing some code for automated testing via GPIB using MPL and PyQt.
> To simulate automated data collection while debugging the program, I have
> added a for loop (see below) after reading in a data file that plots each
> point one by one. When I run the program in Linux, I see each point appear
> on the canvas one by one as designed, but when I run the same code in
> Windows, nothing shows up on the canvas during the for loop. Instead, once
> the loop has completed, all points appear simulataneously. Is there any
> reason the why calls to canvas.draw() show nothing when run in Windows? I'm
> really lost on this one and would appreciate it someone can tell me what I'm
> doing wrong. If you need more info on what I'm doing, please let me know.
It would help if we could see the whole program. Ie, I assume this is
a pure qt app with no import of pyplot/pylab, but w/o seeing any code
I cannot be sure. Also, check the qt examples at
http://matplotlib.sourceforge.net/examples/animation/index.html
and see if they work on windows. If so, perhaps you can borrow
inspiration from them. If not, perhaps we need to do something
different for qt/windows animation.
JDH
JDH
from pylab import *
from time import sleep
x = linspace(0,10,10)
y = linspace(0,10,10)
ion()
ax = subplot(111,autoscale_on=True)
for i in range(0,len(x)):
line = plot([x[i]], [y[i]],'-o')
draw()
sleep(4)
import sys, os, random
from PyQt4 import QtGui, QtCore
#from pylab import *
from numpy import arange, sin, pi, linspace
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
progname = os.path.basename(sys.argv[0])
progversion = "0.1"
class MyMplCanvas(FigureCanvas):
"""Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
# We want the axes cleared every time plot() is called
self.axes.hold(False)
self.compute_initial_figure()
#
FigureCanvas.__init__(self, fig)
self.setParent(parent)
FigureCanvas.setSizePolicy(self,
QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
#def compute_initial_figure(self):
# pass
class MyStaticMplCanvas(MyMplCanvas):
"""Simple canvas with a sine plot."""
def compute_initial_figure(self):
t = arange(0.0, 3.0, 0.01)
s = sin(2*pi*t)
self.axes.plot(t, s)
class MyDynamicMplCanvas(MyMplCanvas):
"""A canvas that updates itself every second with a new plot."""
def __init__(self, *args, **kwargs):
MyMplCanvas.__init__(self, *args, **kwargs)
timer = QtCore.QTimer(self)
QtCore.QObject.connect(timer, QtCore.SIGNAL("timeout()"), self.update_figure)
timer.start(1000)
def compute_initial_figure(self):
#self.axes.plot([0, 1, 2, 3], [1, 2, 0, 4], 'r')
print 'nothing'
def update_figure(self):
# Build a list of 4 random integers between 0 and 10 (both inclusive)
self.axes.hold(True)
x = linspace(0,11,50)
y = linspace(0,10,50)
for i in range(0,len(y)):
self.axes.plot([x[i]], [y[i]], 'ro')
print i, x[i], y[i]
self.draw()
class ApplicationWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.setWindowTitle("application main window")
self.file_menu = QtGui.QMenu('&File', self)
self.file_menu.addAction('&Quit', self.fileQuit,
QtCore.Qt.CTRL + QtCore.Qt.Key_Q)
self.menuBar().addMenu(self.file_menu)
self.help_menu = QtGui.QMenu('&Help', self)
self.menuBar().addSeparator()
self.menuBar().addMenu(self.help_menu)
self.help_menu.addAction('&About', self.about)
self.main_widget = QtGui.QWidget(self)
l = QtGui.QVBoxLayout(self.main_widget)
sc = MyStaticMplCanvas(self.main_widget, width=5, height=4, dpi=100)
dc = MyDynamicMplCanvas(self.main_widget, width=5, height=4, dpi=100)
l.addWidget(sc)
l.addWidget(dc)
self.main_widget.setFocus()
self.setCentralWidget(self.main_widget)
self.statusBar().showMessage("All hail matplotlib!", 2000)
def fileQuit(self):
self.close()
def closeEvent(self, ce):
self.fileQuit()
def about(self):
QtGui.QMessageBox.about(self, "About %s" % progname,
u"""%(prog)s version %(version)s
Copyright \N{COPYRIGHT SIGN} 2005 Florent Rougon, 2006 Darren Dale
This program is a simple example of a Qt4 application embedding matplotlib
canvases.
It may be used and modified with no restriction; raw copies as well as
modified versions may be distributed without limitation."""
% {"prog": progname, "version": progversion})
qApp = QtGui.QApplication(sys.argv)
aw = ApplicationWindow()
aw.setWindowTitle("%s" % progname)
aw.show()
sys.exit(qApp.exec_())
#qApp.exec_()
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users