Problem with show()

Hi,
Today I tried to run some code in my new notebook, but I only got blank figures
and high CPU usage as a result. This code did run on my previous laptop. I can
reproduce this behavior with the following code at the bottom of this message.
The backtrace (also at the bottom this message) points to show() as the cause of
the problem. The reason I have show() at the top is because in my code the call
to plot() is done within a loop (I reuse the same figure for multiple plots). I
still have to check all software versions in detail from the older laptop, but I
wanted to ask here in case this was a known problem. I have ipython from git,
and matplotlib 1.0, this is a 64 bit OS (Ubuntu 10.10). Matplotlib was installed
from source. In the other laptop (Ubuntu 10.4, 32 bits) there's also ipython
from git (although an older revision) and matplotlib 1.0 compiled from source.

Regards,

Jorge

example code showing the problem
----8<-------------------------
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

fig, ax = plt.subplots(1,1)
plt.show()
data = np.random.randn(10)
ax.plot(data)
fig.canvas.draw()
----8<-------------------------

backtrace after hitting CTRL-C
----8<-------------------------
In [2]: run doct/intrinsic-images/test_show.py
^C---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
/home/jscandal/sw/python/doct/intrinsic-images/test_show.py in <module>()
      5
      6 fig, ax = plt.subplots(1,1)
----> 7 plt.show()
      8 data = np.random.randn(10)
      9 ax.plot(data)

/home/jscandal/lib/python2.6/site-packages/matplotlib/backends/backend_gtk.pyc
in show(mainloop)
     76 if mainloop and gtk.main_level() == 0 and \
     77 len(Gcf.get_all_fig_managers())>0:
---> 78 gtk.main()
     79
     80 def new_figure_manager(num, *args, **kwargs):

KeyboardInterrupt:

Hi,
Today I tried to run some code in my new notebook, but I only got blank figures
and high CPU usage as a result. This code did run on my previous laptop. I can
reproduce this behavior with the following code at the bottom of this message.
The backtrace (also at the bottom this message) points to show() as the cause of
the problem. The reason I have show() at the top is because in my code the call
to plot() is done within a loop (I reuse the same figure for multiple plots). I
still have to check all software versions in detail from the older laptop, but I
wanted to ask here in case this was a known problem. I have ipython from git,
and matplotlib 1.0, this is a 64 bit OS (Ubuntu 10.10). Matplotlib was installed
from source. In the other laptop (Ubuntu 10.4, 32 bits) there's also ipython
from git (although an older revision) and matplotlib 1.0 compiled from source.

Regards,

Jorge

For this to work, you need to be in matplotlib's interactive mode, either by running ipython with the -pylab option, or by calling plt.ion() before your call to show(). In either of these cases, your example code works for me with ipython from git, mpl from svn, and using drag/drop to enter the code in ipython. I am also on ubuntu 10.10, 64-bit, with gtkagg backend.

Eric

···

On 10/05/2010 01:00 PM, Jorge Scandaliaris wrote:

example code showing the problem
----8<-------------------------
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

fig, ax = plt.subplots(1,1)
plt.show()
data = np.random.randn(10)
ax.plot(data)
fig.canvas.draw()
----8<-------------------------

backtrace after hitting CTRL-C
----8<-------------------------
In [2]: run doct/intrinsic-images/test_show.py
^C---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
/home/jscandal/sw/python/doct/intrinsic-images/test_show.py in<module>()
       5
       6 fig, ax = plt.subplots(1,1)
----> 7 plt.show()
       8 data = np.random.randn(10)
       9 ax.plot(data)

/home/jscandal/lib/python2.6/site-packages/matplotlib/backends/backend_gtk.pyc
in show(mainloop)
      76 if mainloop and gtk.main_level() == 0 and \
      77 len(Gcf.get_all_fig_managers())>0:
---> 78 gtk.main()
      79
      80 def new_figure_manager(num, *args, **kwargs):

KeyboardInterrupt: