Hello,
I need write a program with 8 plots acquiring datas in 100ms per point
in a dynamic mode.
I wrote a test program (dynamic_plot_double_v1.py) but I am sure that
it is not the right thing. The plots slow down with the increase the
data arrays. The time to close the application incluse with data array
too.
Can the matplotlib plot very fast in a dynamic mode? Can Someone give
me directions?
Thanks advanced.
Carlos Antonio Neves
LAIA - Laboratório de Automação e Instrumentação Analítica
http://allchemy2.iq.usp.br/cll/moin.cgi/LAIA_2fEnglish
Instituto de Química da Universidade de São Paulo - IQ-USP
···
####################################################################################
#!/usr/bin/env python
"""
dynamic_plot_double_v1.py
Dynamic plot test with two graphics.
"""
import random
import time
import gobject
from pylab import *
from matplotlib.numerix import arange
class MyPlotDouble:
def __init__(self):
self.x = [0]
self.y = [0]
self.z = [0]
self.tempo_limite_janela_s = 10
ioff()
self.fig = figure(1)
self.ax1 = self.fig.add_subplot(211)
self.ax2 = self.fig.add_subplot(212)
self.ylines = self.ax1.plot(self.x, self.y, 'go-', label='line
y', linewidth=2)
self.zlines = self.ax2.plot(self.x, self.z, 'ro-', label='line
z', linewidth=2)
self.ax1.grid(True)
self.ax1.set_xlim( (0, self.tempo_limite_janela_s) )
self.ax1.set_ylim( (0, 254) )
#self.ax1.set_xlabel('time')
self.ax1.set_ylabel('value #1')
self.ax1.set_title('Noise #1')
self.ax2.grid(True)
self.ax2.set_xlim( (0, self.tempo_limite_janela_s) )
self.ax2.set_ylim( (0, 254) )
self.ax2.set_xlabel('time')
self.ax2.set_ylabel('value #2')
self.ax2.set_title('Noise #2')
self.manager = get_current_fig_manager()
self.tstart = time.time()
gobject.timeout_add(200, self.updatefig)
show()
def updatefig(self):
self.y.append(random.randint(0, 254))
self.z.append(random.randint(0, 254))
self.x.append(time.time() - self.tstart)
self.ylines[0].set_data(self.x, self.y)
self.zlines[0].set_data(self.x, self.z)
if (self.x[len(self.x)-1] >= self.tempo_limite_janela_s):
self.tempo_limite_janela_s = self.tempo_limite_janela_s +
self.tempo_limite_janela_s
self.ax1.set_xlim( (0, self.tempo_limite_janela_s) )
self.ax2.set_xlim( (0, self.tempo_limite_janela_s) )
self.manager.canvas.draw()
print "%f %i %i %fms\n" % (self.x[len(self.x)-1],
self.y[len(self.y)-1],
self.z[len(self.z)-1],
(self.x[len(self.x)-1] -
self.x[len(self.x) - 2])*1000),
return True
app = MyPlotDouble()
####################################################################################