You're already using "ax.legend", what kind of OO way do you want?
Instead of calling plt.legend, you may do ax.legend([s],[str(i)]) Or, if you know what you're doing, you can do leg = ax.legend([s],[''], loc=0) and in the for loop, leg.texts[0].set_text(str(i)) Regards, -JJ On Thu, Feb 11, 2010 at 5:56 AM, Jorge Scandaliaris <jorgesmbox...@yahoo.es> wrote: > Hi, > I am re-using a scatter plot in the same figure for interactively displaying > results without ending up with 30 windows open. The legend is relevant, and so > it must be also updated. So far the only way I found was to use the > set_label() > method and then using plt.legend(). Is this the only way to get a legend > updated > from a label? I am curious, since generally there is the pyplot way and a more > OO way of achieving things, but I could't find it this time. > > The snippet below shows what I am using right now: > > import numpy as np > import scipy as sp > import matplotlib as mpl > import matplotlib.pyplot as plt > > data = np.random.randn(3,10) > fig = plt.figure() > ax = fig.add_subplot(111) > s, = ax.plot([]) > ax.axis([0,10,-1,1]) > ax.legend([s],[''], loc=0) > for i in range(data.shape[0]): > s.set_data([np.arange(data.shape[1]),data[i]]) > s.set_label(str(i)) > plt.legend() > plt.draw() > plt.ginput(timeout=0) > > > > ------------------------------------------------------------------------------ > SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, > Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW > http://p.sf.net/sfu/solaris-dev2dev > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ------------------------------------------------------------------------------ SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users