interacting with data plot


I'll have to play with this a bit to see if it works for what I want to

From: John Hunter [mailto:jdh2358@…287…]
Sent: Friday, June 08, 2007 12:41 PM
To: Trevis Crane
Subject: Re: [Matplotlib-users] interacting with data plot

> Hi all,
> I have a plot of data that I am enabling the user to interact with.


> 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


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

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.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f'%(xs[dataind],



-----Original Message-----
On 6/8/07, Trevis Crane <t_crane@...1614...> wrote:
                transform=ax.transAxes, va='top')
        ax.set_ylim(-0.5, 1.5)
        print 'plotted'
    show() # oops, we need a way to raise figures created in callbacks
    return True

fig.canvas.mpl_connect('pick_event', onpick1)