Thanks! I'll have to play with this a bit to see if it works for what I want to do.
> -----Original Message----- > From: John Hunter [mailto:[EMAIL PROTECTED] > Sent: Friday, June 08, 2007 12:41 PM > To: Trevis Crane > Cc: matplotlib-users@lists.sourceforge.net > Subject: Re: [Matplotlib-users] interacting with data plot > > On 6/8/07, Trevis Crane <[EMAIL PROTECTED]> wrote: > > > > > > > > > > Hi all, > > > > > > > > I have a plot of data that I am enabling the user to interact with. That > > is, I want them to be able to pick a point, and then have a new plot pop up > > in a different figure showing more info about that point. > > Here is an example that I just committed to svn as examples/pick_event_demo2.py > > It made me realize that despite all my protestations not to repeatedly > call show, we do not have a backend dependent way to raise new figures > created in mpl callbacks. Since we've mostly made show bullet-proof > to repeated calls (because we don't restart the mainloops) this works, > but we do need a backend independent way to raise figures. > > One approach would be to have the figure creation function (eg in the > backend) attach a method show() that raises the figure when called, eg > fig.show() > > In any case, here is the example code, also attached in case the lines > get wrapped > > > """ > compute the mean and stddev of 100 data sets and plot mean vs stddev. > When you click on one of the mu, sigma points, plot the raw data from > the dataset that generated the mean and stddev > """ > import numpy > from pylab import figure, show > > > X = numpy.random.rand(100, 1000) > xs = numpy.mean(X, axis=1) > ys = numpy.std(X, axis=1) > > fig = figure() > ax = fig.add_subplot(111) > ax.set_title('click on point to plot time series') > line, = ax.plot(xs, ys, 'o', picker=5) # 5 points tolerance > > > def onpick1(event): > > if event.artist!=line: return True > > N = len(event.ind) > if not N: return True > > figi = figure() > for subplotnum, dataind in enumerate(event.ind): > ax = figi.add_subplot(N,1,subplotnum+1) > ax.plot(X[dataind]) > ax.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f'%(xs[dataind], ys[dataind]), > transform=ax.transAxes, va='top') > ax.set_ylim(-0.5, 1.5) > ax.figure.canvas.draw() > print 'plotted' > show() # oops, we need a way to raise figures created in callbacks > return True > > fig.canvas.mpl_connect('pick_event', onpick1) > > show() ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users