Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most lightweight way to plot streaming data in python

To give you a sense of what I'm looking for, it looks like this:

Up until now I have used matplotlib for all my plotting, and timing hasn't been critical (it's been done in postprocessing).

I'm wondering if there is a lighter weight way to plot other than shifting my data to the left and redrawing the entire plot.

like image 616
Chris Avatar asked Jan 18 '13 01:01

Chris


1 Answers

Have a look at the Matplotlib Animations Examples. The main trick is to not completely redraw the graph but rather use the OO interface of matplotlib and set the x/ydata of the plot-line you created. If you've integrated your plot with some GUI, e.g., GTK, then definitely do it like proposed in the respective section of the plot, otherwise you might interfere with the event-loop of your GUI toolkit.

For reference, if the link ever dies:

from pylab import *
import time

ion()

tstart = time.time()               # for profiling
x = arange(0,2*pi,0.01)            # x-array
line, = plot(x,sin(x))
for i in arange(1,200):
    line.set_ydata(sin(x+i/10.0))  # update the data
    draw()                         # redraw the canvas

print 'FPS:' , 200/(time.time()-tstart)
like image 90
Thorsten Kranz Avatar answered Sep 21 '22 03:09

Thorsten Kranz