On Fri, Jul 3, 2009 at 8:32 AM, guillaume ranquet <granq...@wyplay.com>wrote:

> Hi list,
>
> I'm trying to get a dynamic plot running.
> I'm stuck at feeding the data to the lines.
>
> basically I've a callback that receives a (y,x1,x2) tuple and I would
> like to add the 2 points to the two matplotlib.lines of the figure.
>
> should I handle a copy of xdata/ydata and gives the updated set to
> set_x/ydata() for one point?
> I tried to get_data() and append to it, but It's a MaskedArray and I
> guess it means its a really bad idea to try this way.
>
> probably a new class inheriting figure and overriding
> get_data()//set_data() could do the trick?
>
>
> any advice on a _clean_ design I could use?
>

You can add a value to an array using np.concatenate:

x,y = line.get_data()
x = np.concatenate((x, [x0]))
y = np.concatenate((y, [y0]))
line.set_data([x,y])

This is rather inefficient however if you're adding lots of points or if
there are just a lot of point in x any in general.  If you know how many
points you're going to end up with, you could create mostly empty
MaskedArrays and keep the extra points masked until you get the data.

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to