interactive python session with matplotlib

Hi All,

I have what I think is a basic question. I want to have an interactive python script/code which uses matplotlib. For example, the script first asks what data set to use, then when received, it does some analysis routines, and then makes some plots. To launch the plot, my I have in my routine

> #!/usr/bin/python (I am not running in interactive mode, rather I made an executable script)
> import matplotlib.pyplot as plt

some analysis stuff

> plt.show()

after the plt.show() command, the terminal I run the script from becomes unresponsive until I close plot I made. However, I would like instead to be able to continue interacting with the program. For example, choosing a fitting window based upon the first plot. But I don't want to have to close down the plot to do this. So my question(s):

1 - how do I continue to interact with the terminal (and my program asking for more imput) after the plt.show() command has been issued?

2 - is there an alternative command I can use instead of plt.show() which does not lock up the terminal?

3 - is it possible to launch more than one matplotlib plotting window with the same interactive python session (executable python script)?

I thought perhaps the answer to my question would be to have a sub-script executed by my main one which generates the various plots I want, where each successive plot requires user input after viewing the previous ones.

Any thoughts/advice are appreciated.

Thanks,

Andre

IPython can remedy all your wonderings :slight_smile:

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

···

On Thu, Sep 24, 2009 at 7:25 PM, Andre Walker-Loud <walksloud@…287…> wrote:

Hi All,

I have what I think is a basic question. I want to have an

interactive python script/code which uses matplotlib. For example,

the script first asks what data set to use, then when received, it

does some analysis routines, and then makes some plots. To launch the

plot, my I have in my routine

#!/usr/bin/python (I am not running in interactive mode, rather I

made an executable script)

import matplotlib.pyplot as plt

some analysis stuff

plt.show()

after the plt.show() command, the terminal I run the script from

becomes unresponsive until I close plot I made. However, I would like

instead to be able to continue interacting with the program. For

example, choosing a fitting window based upon the first plot. But I

don’t want to have to close down the plot to do this. So my

question(s):

1 - how do I continue to interact with the terminal (and my program

asking for more imput) after the plt.show() command has been issued?

2 - is there an alternative command I can use instead of plt.show()

which does not lock up the terminal?

3 - is it possible to launch more than one matplotlib plotting window

with the same interactive python session (executable python script)?

I thought perhaps the answer to my question would be to have a sub-

script executed by my main one which generates the various plots I

want, where each successive plot requires user input after viewing the

previous ones.

Any thoughts/advice are appreciated.

Thanks,

Andre


Come build with us! The BlackBerry® Developer Conference in SF, CA

is the only developer event you need to attend this year. Jumpstart your

developing skills, take BlackBerry mobile applications to market and stay

ahead of the curve. Join us from November 9-12, 2009. Register now!

http://p.sf.net/sfu/devconf


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Gökhan

IPython can remedy all your wonderings :slight_smile:

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


Gökhan

Hi Gökhan,

I am not very familiar with iPython (I am not opposed to learning either).

What I have in mind is writing code that I can call from a terminal, as opposed to interactively as with iPython. However, in iPython, can you have a module/script running, and asking me as the user for input? I have assumed iPython is similar to an interactive Python interpreter. With the knowledge I have, I can not, while in interactive mode, launch a sub routine that will ask me for input. Is this possible to do (in either Python or iPython)?

Thanks,

Andre

···

On Sep 24, 2009, at 8:44 PM, Gökhan Sever wrote:

On Thu, Sep 24, 2009 at 7:25 PM, Andre Walker-Loud <walksloud@…287…> wrote:

Hi All,

I have what I think is a basic question. I want to have an
interactive python script/code which uses matplotlib. For example,
the script first asks what data set to use, then when received, it
does some analysis routines, and then makes some plots. To launch the
plot, my I have in my routine

#!/usr/bin/python (I am not running in interactive mode, rather I
made an executable script)
import matplotlib.pyplot as plt

some analysis stuff

plt.show()

after the plt.show() command, the terminal I run the script from
becomes unresponsive until I close plot I made. However, I would like
instead to be able to continue interacting with the program. For
example, choosing a fitting window based upon the first plot. But I
don’t want to have to close down the plot to do this. So my
question(s):

1 - how do I continue to interact with the terminal (and my program
asking for more imput) after the plt.show() command has been issued?

2 - is there an alternative command I can use instead of plt.show()
which does not lock up the terminal?

3 - is it possible to launch more than one matplotlib plotting window
with the same interactive python session (executable python script)?

I thought perhaps the answer to my question would be to have a sub-
script executed by my main one which generates the various plots I
want, where each successive plot requires user input after viewing the
previous ones.

Any thoughts/advice are appreciated.

Thanks,

Andre


Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf


Matplotlib-users mailing list
Matplotlib-users@…1064…t
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

IPython can remedy all your wonderings :slight_smile:

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


Gökhan

Just give it a try (http://ipython.scipy.org/moin/)

I don’t think you will ever look back the regular Python interpreter. (When I first start with Python, I only use it for about less than a day :slight_smile:

This page is very explanatory of what IPython is capable of

http://ipython.scipy.org/doc/stable/html/overview.html

This is a great audio-visual tutorial about IPython by Jeff Rush
A Demonstration of the ‘IPython’ Interactive Shell

and finally I recommend you to watch some of the SciPy09 videos to see how other people using IPython interactively. Since we are corresponding under matplotlib roof, wouldn’t be fair it don’t suggest you to watch John Hunter’s Advanced topics in matplotlib tutorial.

···

On Thu, Sep 24, 2009 at 10:47 PM, Andre Walker-Loud <walksloud@…287…> wrote:

IPython can remedy all your wonderings :slight_smile:

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


Gökhan

Hi Gökhan,

I am not very familiar with iPython (I am not opposed to learning either).

What I have in mind is writing code that I can call from a terminal, as opposed to interactively as with iPython. However, in iPython, can you have a module/script running, and asking me as the user for input? I have assumed iPython is similar to an interactive Python interpreter. With the knowledge I have, I can not, while in interactive mode, launch a sub routine that will ask me for input. Is this possible to do (in either Python or iPython)?

Thanks,

Andre

Hi Gökhan,

Thanks. I will start playing around with iPython.

Andre

···

On Sep 25, 2009, at 1:22 AM, Gökhan Sever wrote:

On Thu, Sep 24, 2009 at 10:47 PM, Andre Walker-Loud <walksloud@…287…> wrote:

IPython can remedy all your wonderings :slight_smile:

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


Gökhan

Hi Gökhan,

I am not very familiar with iPython (I am not opposed to learning either).

What I have in mind is writing code that I can call from a terminal, as opposed to interactively as with iPython. However, in iPython, can you have a module/script running, and asking me as the user for input? I have assumed iPython is similar to an interactive Python interpreter. With the knowledge I have, I can not, while in interactive mode, launch a sub routine that will ask me for input. Is this possible to do (in either Python or iPython)?

Thanks,

Andre

Just give it a try (http://ipython.scipy.org/moin/)

I don’t think you will ever look back the regular Python interpreter. (When I first start with Python, I only use it for about less than a day :slight_smile:

This page is very explanatory of what IPython is capable of
http://ipython.scipy.org/doc/stable/html/overview.html

This is a great audio-visual tutorial about IPython by Jeff Rush
A Demonstration of the ‘IPython’ Interactive Shell

and finally I recommend you to watch some of the SciPy09 videos to see how other people using IPython interactively. Since we are corresponding under matplotlib roof, wouldn’t be fair it don’t suggest you to watch John Hunter’s Advanced topics in matplotlib tutorial.

Andre Walker-Loud wrote:

IPython can remedy all your wonderings :slight_smile:

I second that!

What I have in mind is writing code that I can call from a terminal, as opposed to interactively as with iPython.

you can call ipython with a script as a command line parameter:

ipython TheScriptToRun.py

so you can make an alias, or a little shell r batch script that calls ipython with your script.

However, in iPython, can you have a module/script running, and asking me as the user for input?

sure -- either with simple raw_input and friends, or with the GUI toolkit of your choice (GTK, wxPython, etc), jsut use the same one as you use for MPL.

The key here is that GUI toolkits run a Mainloop() to process user input, and once you've started that, they block python until it's done.

What Ipython does is (optionally) start up the GUI toolkit in another thread, so that the main interactive prompt is not blocked. It's handy for mixing an interactive prompt and GUI stuff, even if you aren't using MPL. Plus you get all the other nifty iPython features.

Give it try -- it's wonderful.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...