I tryed yesterday to play a little with your script.
Thus it goes slower and slower.
···
De : Alexander Hupfer
[mailto:sonium@…287…]
Envoyé : jeudi 7 janvier 2010 03:36
C****c :
matplotlib-users@…1220…sts.sourceforge.net
Objet : Re: [Matplotlib-users] Colorbar embedding in qt4
I isolated the problem a bit
more. For some reason drawing gets slower and slower with each plot drawn.
from os import sys
from time import time
from PyQt4 import QtGui, QtCore
import matplotlib
matplotlib.use(‘QT4Agg’)
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as
FigureCanvas
from matplotlib.figure import Figure
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 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(0)
self.firstrun = True
self.colorbar = None
self.time = time()
self.p = None
def compute_initial_figure(self):
pass
def update_figure(self):
self.p =
self.axes.scatter([1,2,3],[4,5,6], c = range(3), animated=True)
self.axes.set_xlabel(‘psi’)
self.axes.set_ylabel(‘delta’)
if self.firstrun == True:
self.colorbar = self.axes.figure.colorbar(self.p)
self.firstrun = False
self.colorbar.set_clim(vmin=0,vmax=2)
self.colorbar.draw_all()
self.colorbar.set_label(‘time [abtr.
]’)
self.draw()
newtime = time()
print newtime - self.time
self.time = newtime
class ApplicationWindow(QtGui.QMainWindow):
def init(self):
QtGui.QMainWindow.init(self)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.main_widget =
QtGui.QWidget(self)
l = QtGui.QVBoxLayout(self.main_widget)
dc =
MyDynamicMplCanvas(self.main_widget, width=5, height=4, dpi=100)
l.addWidget(dc)
self.main_widget.setFocus()
self.setCentralWidget(self.main_widget)
qApp = QtGui.QApplication(sys.argv)
aw = ApplicationWindow()
aw.setWindowTitle(“%s” % “Slow!”)
aw.setGeometry(100,100,800,600)
aw.show()
sys.exit(qApp.exec_())
On Mon, Jan 4, 2010 at 3:36 PM, Alexander Hupfer <sonium@…287…> wrote:
Ok, here is the code as a whole. I think it’s still short
enough to ilustrate the problem. Just start it with the datafile
“elips” as an argument
http://dl.dropbox.com/u/226980/elipsometry.tar.gz
The timer shows how long each render cycle takes. The time seems to grow with
number of cycles rendered even when no more points are added (the points are
calculated with a continous rate in a background thread and are about 300
total).
On Sun, Jan 3, 2010 at 8:16 PM, John Hunter <jdh2358@…287…> wrote:
On Sun, Jan 3, 2010 at 7:02 PM, Alexander Hupfer <sonium@…287…> wrote:
Thanks I got it fixed.
This leads to the follow up question:
What is the right way to keep an application responsive while the graph is
drawn?
Drawing a scatter plot with 300 points seems to take a while. I guess I
need
to launch the drawing in another thread but don’t know exactly how to do
this and only find examples of doing calculations in the background and
not
actual widget interaction.
You posted some real code and a traceback, which helped move
the ball
forward. What we really need to see to help you though is a complete,
free-standing example, that we can run on our machines, which exposes
the problem.
JDH