interactive plots in ipython -pylab are delayed until ipython prompt

I have successfully used ipython -pylab under w32 python, but under the
builtin ipython under ubuntu 9 and 10, the graphics display thread seems to
block until the ipython command line - as if the threading (internal to
ipython etc) is not happening.

For example if the following is pasted in, the plot appears after 2 seconds,
instead of straight away, as it used to in w32 python 2.6, (and I think, but
am not sure, in earlier linux pythons). The reason I want this feature is
to show intermediate
results of long computations, without blocking, as would happen in straight
python or ipython. See version numbers at end.

import time
# Note - this version is meant to be pasted!

print('When pasted in to ipython -pylab, the plot should appear immediately,
'
      ' then the ipython prompt after sleep(2): but the plot waits until the
prompt!')
plot([3,4], hold=0)
ion()
show()
time.sleep(2)

Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
IPython 0.10
matplotlib.__version__ Out[3]: '0.99.1.1'

···


View this message in context: http://old.nabble.com/interactive-plots-in-ipython--pylab-are-delayed-until-ipython-prompt-tp29123816p29123816.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Any chance you can test this with the latest release 1.0.0?

JDH

···

On Fri, Jul 9, 2010 at 9:52 PM, bdb112 <boyd.blackwell@...634...> wrote:

python or ipython. See version numbers at end.

import time
# Note - this version is meant to be pasted!

print('When pasted in to ipython -pylab, the plot should appear immediately,
'
' then the ipython prompt after sleep(2): but the plot waits until the
prompt!')
plot([3,4], hold=0)
ion()
show()
time.sleep(2)

Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
IPython 0.10
matplotlib.__version__ Out[3]: '0.99.1.1

Any chance you can test this with the latest release 1.0.0?
JDH

Tried 1.0.0 but first I should explain what I want more clearly in case I am
missing something.
I want to run a long calculation and have some early results plotted (and
become visible) without needing to close the window as the show() command
now requires. I am happy to run in ipython -pylab to achieve this, and
recognise that the plots might/will be delayed if I use ipython (no pylab)
or straight python.

I also would like the control to suppress the interactive rendering for some
plots, such as those that overlay many curves. When all the curves have
been added to the object (typically by plot()), then I would like them
rendered - this is faster than re-rendering every time a curve is added.

I was able to achieve this with ion(), isinteractive(), and show() in
previous versions.

How should I do it now (especially as show() is now(1.0.0) supposed to
block?

====== Back to your suggestion =======
OK, after aptitude install python-dev tk8.5-dev tcl8.5-dev python-gtk2-dev
1.0.0 can be built

It passes the simple test in the initial post, (good), but is still delayed
in real code - i.e. in script or compiled code.

In the interests of simplicity, I had reduced my test case to the absolute
simplest, equivalent to typing at the command prompt.

Below are two better examples: the first is still very brief, but better
represents real code, and works on ubuntu9.04 and Enthought for w7.
Following is a longer example which is also simplified. I left a few extra
lines commented out to show you what I have tried.

After the code snippets is a list of what versions do and do not work
interactively (as described above).

=======short_test.py==
# graph should appear immediately, the update after 3 secs, prompt at 6 secs
import pylab as pl
import time

def test():
    pl.plot([1,2])
    pl.show()
    time.sleep(3)

print(pl.isinteractive())
pl.ion()
pl.plot([3,4])
pl.show()
time.sleep(3)
test()

==========interactive_plot_test.py===========
""" Test the ability of plots to be interactive - in the sense that
they display as they go, rather than waiting til the command prompt is
reached.
These might well be on different figures, or subplots but I kept it simple.
"""
import pylab as pl
import time

def int_plot():
    print('plot intermediate result')
# pl.figure()
    pl.plot([2,1])
    pl.title('intermediate result')
    
# pl.draw_if_interactive()
# pl.show() #?? (mainloop=False)
    time.sleep(3)

print('When run, the plot should appear immediately, '
      ' then the prompt after sleep(2)')
print('test on "scripted" code - ipython may treat differently')
pl.ion()
pl.plot([3,4], hold=0)
#pl.show()
time.sleep(3)
print('same test on compiled code')
int_plot()

···

=========================

List of what works (and not):

works under ubuntu 9.04 dist (tested under w32 VMPlayer)
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
IPython 0.9.1 matplotlib '0.98.5.2' tkagg backend

works under Win7 Enthought
Python 2.6.4 |EPD 6.1-1 (32-bit)| (r264:75706, Nov 11 2009, 19:42:36) [MSC
v.150
0 32 bit (Intel)]
IPython 0.10 matplotlib: '0.99.1.1' backend_wx.py

*not* under ubuntu 10.04/2.6.5/0.10 with matplotlib 1.0.0 compiled as above
WXAgg: nothing appears until 6 sec, prompt is blocked
TkAgg: nothing appears until 6 sec, prompt is not blocked
GTKAgg: nothing appears until 6 sec, prompt is not blocked

John Hunter-4 wrote:

On Fri, Jul 9, 2010 at 9:52 PM, bdb112 <boyd.blackwell@...634...> wrote:

print('When pasted in to ipython -pylab, the plot should appear
immediately,
'
     ' then the ipython prompt after sleep(2): but the plot waits until
the
prompt!')
plot([3,4], hold=0)
ion()
show()
time.sleep(2)

Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
IPython 0.10
matplotlib.__version__ Out[3]: '0.99.1.1

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
View this message in context: http://old.nabble.com/interactive-plots-in-ipython--pylab-are-delayed-until-ipython-prompt-tp29123816p29129079.html
Sent from the matplotlib - users mailing list archive at Nabble.com.