Hi,
I’m writing a script to plot data being read from a serial connection in real time. I’m trying to use an idle_event callback to continually read the incoming data and plot it. The problem is that the callback is only getting invoked once. I found this page: http://www.scipy.org/Cookbook/Matplotlib/Animations, which suggests using backend-specific stuff. This is intended to be a quick-and-dirty thing though so I was really hoping to avoid that. Here’s my code:
def OnIdle(event):
global xData
global yData
data = ReadSerialData()
if data != None:
yData.append(data)
if len(yData) > GRAPH_WINDOW_SIZE:
del yData[0]
else:
xData.append(len(xData))
line.set_xdata(xData)
line.set_ydata(yData)
pylab.draw()
# end if data != None
end OnIdle
if name == ‘main’:
pylab.ion()
fig = pylab.figure()
ax = fig.add_subplot(1,1,1)
line = ax.add_line(pylab.Line2D([], []))
ax.set_ylim(0, 100)
ax.set_xlim(0, GRAPH_WINDOW_SIZE)
fig.canvas.mpl_connect('idle_event', OnIdle)
pylab.show()
end name == ‘main’
Oh btw, I’m positive that ReadSerialData is not blocking and that it’s making it through the whole idle handler. I’m running on 64 bit Linux with Python 2.6. According to --verbose-helpful, I’m using matplotlib version 0.98.5.2 and GTKAgg version 2.14.1. Am I doing something wrong or do I really need to go backend-specific?
Thanks,
Mark