dynamically updated plots

Hello,

I would like to get periodically updated plots: the data set grows at
some rate (5 numbers/sec) and I would like to update all plots I have
(may be multiple) once in 5 seconds, for example.

I thought of storing Figure objects after creating the plots, then
launch separate thread that would wake up every 5 seconds, copy data
from the source arrays to the Line2D instances (set_data(...)) and call
Figure.draw(..) to update the plot.

I have a few questions to that:

1. Would it be possible to do only shallow copy of the arrays that are
being plotted so that on redrawing the figure, chanes in the datasets
would be picked up automatically? If not, is Line2D.set_data(...) the
right approach?

2. How can I trigger autoscaling of the figure so that all data can be
displayed? Like the one happening when the figure is first drawn; in the
_ideal_ case deynamic autoscaling would be effected only if the graph
has the default zoom level, so that user-zoom is not reset at every redraw.

3. How do I iterate over all Figure instances (and, consequently, Line2D
instances) that are being displayed? Currently, I store Line2D's that
are returned by pylab.plot(...) to acces them later, but I think there
must be a better way,

I hope I was able to clearly express my problem. Do not hesitate to ask
for more information. Best regards,

Vaclav

hi,

1. Would it be possible to do only shallow copy of the arrays that are
being plotted so that on redrawing the figure, chanes in the datasets
would be picked up automatically? If not, is Line2D.set_data(...) the
right approach?

isn't this the way how the plotting is done? in my experience (iirc), the following thing works (x, y1, y2 are numpy arrays):

pylab.ion()

a, = pylab.plot(x,y1)
b, = pylab.plot(x,y2)
...
y1 += 10
y2 += 20

a.set_ydata(y1)
b.set_ydata(y2)
pylab.draw()

y1 += 10
y2 += 20
a.set_ydata(y1)
pylab.draw()

in my experience BOTH plots get updated in this procedure, so i have to do first a deep copy in my case to get rid of these 'unwanted effects'...

best,

···

--
Lubos _@...2056..."
http://www.lubos.vrbka.net

Hi Lubos,

Lubos Vrbka wrote:

1. Would it be possible to do only shallow copy of the arrays that are
being plotted so that on redrawing the figure, chanes in the datasets
would be picked up automatically? If not, is Line2D.set_data(...) the
right approach?
    

isn't this the way how the plotting is done? in my experience (iirc), the following thing works (x, y1, y2 are numpy arrays):

pylab.ion()

a, = pylab.plot(x,y1)
b, = pylab.plot(x,y2)
...
y1 += 10
y2 += 20

a.set_ydata(y1)
b.set_ydata(y2)
pylab.draw()

y1 += 10
y2 += 20
a.set_ydata(y1)
pylab.draw()

in my experience BOTH plots get updated in this procedure, so i have to do first a deep copy in my case to get rid of these 'unwanted effects'...
  

If I understand correctly the len of X and Y will be changing, therefore you may have to use set_data() function of Line2D

set_data(self, *args)
Set the x and y data
ACCEPTS: (array xdata, array ydata)

I seem to remember getting a size mismatch if X and Y grew in length and I tried to use set_xdata() or set_ydata() separately.

YMMV
Steve