forcing prompt draw

To all:

I'm doing a series of fits and want to display the results of each in a
figure before I go to the next one. I currently do roughly something
like this (with a lot left out):

import matplotlib.pyplot as plt
plt.ion()
fig = plt.gcf()
for obsid in obsids:
    <do fitting>
    plt.cla()
    fig = plt.gcf()
    ax = fig.add_axes([0.15,0.1,0.8,0.6])
    ax.plot(x,y)
    plt.draw()
    ans = raw_input('continue? ')
    if ans == 'n':
        break

This works, sort of, except that the first plot is not shown until the
second time I hit the raw_input line. So my question is, is there any
way to make the figure display immediately when the draw() is executed?

Jon

···

--
______________________________________________________________
Jonathan D. Slavin Harvard-Smithsonian CfA
jslavin@...1081... 60 Garden Street, MS 83
phone: (617) 496-7981 Cambridge, MA 02138-1516
cell: (781) 363-0035 USA
______________________________________________________________

The behavior may depend on mpl version and backend, but with 1.0.1 or later, I think something like what you have will work with a little cleanup, e.g.:

import matplotlib.pyplot as plt
import numpy as np

plt.ion()
fig = plt.gcf()
ax = fig.add_axes([0.15,0.1,0.8,0.6])
for i in range(3):
     ax.cla()
     ax.plot(np.random.rand(10))
     plt.draw()
     raw_input("hit a key to proceed")

Eric

···

On 06/24/2011 04:03 AM, Jonathan Slavin wrote:

import matplotlib.pyplot as plt
plt.ion()
fig = plt.gcf()
for obsid in obsids:
     <do fitting>
     plt.cla()
     fig = plt.gcf()
     ax = fig.add_axes([0.15,0.1,0.8,0.6])
     ax.plot(x,y)
     plt.draw()
     ans = raw_input('continue? ')
     if ans == 'n':
         break