Adding points gradually to the plot

Hello all,

I am looking for a way to add points gradually to the plot over time.
Currently, in every iteration, I plot the entire array, like:

fig = plt.figure();
ax = fig.gca()
xs = array([])
ys = array([])
while not done:
  // do some calculation..
  // x=???, y=???
  xs = append(xs,x);
  ys = append(ys,y);
  ax.plot(xs,ys)
  plt.draw()

However, it seems like that the figure is re-drawn completely and so
significantly harms the performance. Rather, I want to add point each
iteration to the plot.

fig = plt.figure();
ax = fig.gca()
while not done:
  // do some calculation..
  // x=???, y=???
  ax.AddPoint(x,y)
  plt.draw() // or update()?

I searched tutorials, but I couldn't find anything related yet. If anyone
knows how, please let me know.

Thanks all,

···

--
View this message in context: http://old.nabble.com/Adding-points-gradually-to-the-plot-tp27148794p27148794.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Instead of appending the points to xs and ys and doing plot(xs,ys) each
time, why not just do plot(x,y)? If you want to save the data in the xs,
ys arrays you can do that without replotting the entire array.

Jon

···

On Wed, 2010-01-13 at 10:14 -0800, Someday... wrote:

Hello all,

I am looking for a way to add points gradually to the plot over time.
Currently, in every iteration, I plot the entire array, like:

fig = plt.figure();
ax = fig.gca()
xs = array()
ys = array()
while not done:
  // do some calculation..
  // x=???, y=???
  xs = append(xs,x);
  ys = append(ys,y);
  ax.plot(xs,ys)
  plt.draw()

However, it seems like that the figure is re-drawn completely and so
significantly harms the performance. Rather, I want to add point each
iteration to the plot.

fig = plt.figure();
ax = fig.gca()
while not done:
  // do some calculation..
  // x=???, y=???
  ax.AddPoint(x,y)
  plt.draw() // or update()?

I searched tutorials, but I couldn't find anything related yet. If anyone
knows how, please let me know.

Thanks all,

--
______________________________________________________________
Jonathan D. Slavin Harvard-Smithsonian CfA
jslavin@...1081... 60 Garden Street, MS 83
phone: (617) 496-7981 Cambridge, MA 02138-1516
cell: (781) 363-0035 USA
______________________________________________________________

Hello,

I think you could do the following

Hello all,

I am looking for a way to add points gradually to the plot over time.
Currently, in every iteration, I plot the entire array, like:

plt.ion() # turn on interactive mode (otherwise the window arises not
before "show()")
fig = plt.figure();
ax = fig.gca()
xs = array()
ys = array()

# plot empty line to generate line object
line, = ax.plot(xs,ys)

while not done:
   // do some calculation..
   // x=???, y=???
   xs = append(xs,x);
   ys = append(ys,y);
   # reset line-data instead of new plotting
   line.set_data(xs, ys)
   plt.draw()

plt.ioff() # turn off interactive mode

In my experience this is better than plotting more and more versions of the
same line or plotting one line for each '(x, y)'-data set ( I think this is
due to the fact that each line-object holds information about its data,
color, linetype, linewidth, marker, ...).

Kind regards,
Matthias

···

On Wednesday 13 January 2010 19:14:08 Someday... wrote:

However, it seems like that the figure is re-drawn completely and so
significantly harms the performance. Rather, I want to add point each
iteration to the plot.

fig = plt.figure();
ax = fig.gca()
while not done:
  // do some calculation..
  // x=???, y=???
  ax.AddPoint(x,y)
  plt.draw() // or update()?

I searched tutorials, but I couldn't find anything related yet. If anyone
knows how, please let me know.

Thanks all,