Interactivity from a script

Hi, I am trying to use a script interacively. It basically

    > needs to do the following.

    > * do some work * plot() * Ask whether to keep the data
    > plotted or not etc.

    > This should be done (initially) at the command line using
    > raw_read(). I don't want to close the plot window to get
    > back to the prompt. In terms of a GUI this would be easy
    > as the dialog would run in the same thread as the plot
    > window. But interactive.py doesn't seem to be the
    > solution.

The best solution for interactive plots is to use the tkagg backend
with interactive set to True in your rc file. Use a standard python
shell or better yet, ipython. Ie, your rc file should have the
settings

backend : TkAgg # the default backend
interactive : True

You can then plot interactively from the shell, and get your prompt
back after each command. Fernando Perez has made some preliminary
extensions for ipython to support interactive use of matplotlib for
TkAgg and may be making an extension for GTKAgg. Very nice for
interactive use. Available from

  http://ipython.scipy.org/

For the 'pylab' extensiosn, save the two files included at the end of
this email to your ~/.ipython dir and start ipython with

  > ipython -p pylab

    > BTW, I am running 0.54.2 as I can't get 0.60.2 to compile
    > under debian stable.

Please build with

  > python setup.py build > build.out

and post the results to the matplotlib-devel list.

Cheers,
JDH

### begin pylab
# -*- Mode: Shell-Script -*- Not really, but it shows comments correctly

···

#***************************************************************************
# Configuration file for ipython -- ipythonrc format
#
# The format of this file is one of 'key value' lines.
# Lines containing only whitespace at the beginning and then a # are ignored
# as comments. But comments can NOT be put on lines with data.
#***************************************************************************

# If this file is found in the user's ~/.ipython directory as ipythonrc-pylab,
# it can be loaded by calling passing the '-profile pylab' (or '-p pylab')
# option to IPython.

# This profile load modules which turn IPython into a very capable environment
# for numerical work, as compatible with Matlab as possible.

# Load the user's basic configuration
include ipythonrc

# Load all additional matlab-like functionality from Numeric and matplotlib
execfile matplotlib_load.py

### end pylab

### begin matplotlib_load.py
# -*- coding: iso-8859-1 -*-
"""matlab-like functionality based on matplotlib and Numeric's MLab.

Load these modules and configure them for interactive use"""

#*****************************************************************************
# Copyright (C) 2004 Fernando P??rez. <fperez@...179...>
#
# Distributed under the terms of the GNU Lesser General Public License (LGPL)
#
# This code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# The full text of the LGPL is available at:
#
# http://www.gnu.org/copyleft/lesser.html
#*****************************************************************************

__author__ = 'Fernando P??rez. <fperez@...179...>'
__license__= 'LGPL'

# Set matplotlib in interactive mode with the TkAgg backend
# THESE MUST BE THE FIRST MATPLOTLIB COMMANDS CALLED!
import matplotlib
matplotlib.use('TkAgg')
matplotlib.interactive(True)

# Now we can continue...

# Load these by themselves so that 'help MODULE' works
import matplotlib.matlab as matlab
# MA (MaskedArray) modifies the Numeric printing mechanism so that huge arrays
# are only summarized and not printed (which could freeze the machine for a
# _long_ time).
import MA

# Bring all of the numeric and plotting commands to the toplevel namespace
from IPython.numutils import *
from matplotlib.matlab import *

print """Welcome to pylab, a matlab-like python environment.
    help(Numeric) -> help on NumPy, Python's basic numerical library.
    help(matlab) -> help on matlab compatible commands from matplotlib.
    help(plotting) -> help on plotting commands.
    """
### end matplotlib_load.py