views:

450

answers:

3

Hi all,

I have been developing a GUI for reading continuous data from a serial port. After reading the data, some calculations are made and the results will be plotted and refreshed (aka dynamic plotting). I use the wx backend provided in the matplotlib for this purposes. To do this, I basically use an array to store my results, in which I keep appending it to, after each calculation, and replot the whole graph. To make it "dynamic", I just set the x-axis lower and upper limits for each iteration. Something like found in:

http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/

The problem, however, is that since the data is continuous, and if I keep plotting it, eventually the system memory will run out and system will crash. Is there any other way I can plot my result continuously?

+2  A: 

To do this, I basically use an array to store my results, in which I keep appending it to

Try limiting the size of this array, either by deleting old data or by deleting every n-th entry (the screen resolution will prevent all entries to be displayed anyway). I assume you write all the data to disk so you won't lose anything.

Also, analise your code for memory leaks. Stuff you use and don't need anymore but that doesn't get garbage-collected because you still have a reference to it.

Toni Ruža
I have been thinking of similar thing; deleting/limiting the size of the array. You are right, besides plotting, the data will be saved into a file in the disk. Still, if possible, I would like to create a feature, in which, the user can view the whole/certain range of plotting (in addition to dynamic plotting which I set the x-axis limit).
teonghan
A: 

I have created such a component with pythons Tkinter. The source is here.

Basically, you have to keep the plotted data somewhere. You cannot keep an infinite amount of data points in memory, so you either have to save it to disk or you have to overwrite old data points.

Otto Allmendinger
Yeah, I agree, infinite looping/appending is a disaster. Thanks for sharing the code, will have a look at it.
teonghan
A: 

Data and representation of data are two different things. You might want to store your data to disk if it's important data to be analyzed later, but only keep a fixed period of time or the last N points for display purposes. You could even let the user pick the time frame to be displayed.

Matt
Maybe something like this?1. Dynamic plotting: fixed x-range, limit the size of array by deleting unused values.2. Every data being write into a file in disk3. User defined plotting: read from the previously-saved-in-the-disk data and plot it
teonghan
Something like that. In point 1, you probably mean "oldest" rather than "unused" :)
Matt