Interactive use of matplotlib in ipython

Hello,

I would like to build a bit of an interactive fitter with matplotlib and ipython (in pylab environment). I would like to have a a function, which takes x and y as input, then plots these and fits a line to it (just numpy polyfit). if I click a point it will be removed from the fit pool and the line will be refitted (optionally after pressing 'f'). when I'm done I can press 'q' or close the window and the function will come to an end and spit out the fitting parameter.
I tried this a year or two ago and I had terrible problems with getting stopping the event loop and waiting for the interactive part to finish and then finish the function. I'm running os 10.6 and use the wx backend (or mac os x, if that's easier). Can you point me to an example or give me a crude overview of how to do that in the right way. Is that understandable?

Cheers
    Wolfgang

Take a look at

  http://matplotlib.sourceforge.net/examples/event_handling/poly_editor.html

You can use the 'i' and 'd' keys to insert and delete vertexes, can
click and drag them to move them.

See also the event handling tutorial at

  http://matplotlib.sourceforge.net/users/event_handling.html

JDH

···

On Wed, Feb 17, 2010 at 7:42 AM, Wolfgang Kerzendorf <wkerzendorf@...982...> wrote:

Hello,

I would like to build a bit of an interactive fitter with matplotlib and ipython (in pylab environment). I would like to have a a function, which takes x and y as input, then plots these and fits a line to it (just numpy polyfit). if I click a point it will be removed from the fit pool and the line will be refitted (optionally after pressing 'f'). when I'm done I can press 'q' or close the window and the function will come to an end and spit out the fitting parameter.
I tried this a year or two ago and I had terrible problems with getting stopping the event loop and waiting for the interactive part to finish and then finish the function. I'm running os 10.6 and use the wx backend (or mac os x, if that's easier). Can you point me to an example or give me a crude overview of how to do that in the right way. Is that understandable?

That is really awesome, I wrote myself a little script today using the poly_editor, data browser and the widgets. This is really cool.

I have one problem however, with the widgets I have buttons to switch between different data sets and like in the button demo i just update the plotdata rather than creating a new plot object. I then try to ax.autoscale_view, but that doesnt do anything even after a fig.canvas.draw() update. any ideas?

Cheers

Wolfgang

···

On Thu, Feb 18, 2010 at 1:18 AM, John Hunter <jdh2358@…287…> wrote:

On Wed, Feb 17, 2010 at 7:42 AM, Wolfgang Kerzendorf > > <wkerzendorf@…982…> wrote:

Hello,

I would like to build a bit of an interactive fitter with matplotlib and ipython (in pylab environment). I would like to have a a function, which takes x and y as input, then plots these and fits a line to it (just numpy polyfit). if I click a point it will be removed from the fit pool and the line will be refitted (optionally after pressing ‘f’). when I’m done I can press ‘q’ or close the window and the function will come to an end and spit out the fitting parameter.

I tried this a year or two ago and I had terrible problems with getting stopping the event loop and waiting for the interactive part to finish and then finish the function. I’m running os 10.6 and use the wx backend (or mac os x, if that’s easier). Can you point me to an example or give me a crude overview of how to do that in the right way. Is that understandable?

Take a look at

http://matplotlib.sourceforge.net/examples/event_handling/poly_editor.html

You can use the ‘i’ and ‘d’ keys to insert and delete vertexes, can

click and drag them to move them.

See also the event handling tutorial at

http://matplotlib.sourceforge.net/users/event_handling.html

JDH