unable to use matplotlib from inside emacs on windows

Whenever I try to use matplotlib from a python session inside emacs, python freezes. What I do is start GNU Emacs version 21.1.3 for Windows, do ESC-x shell and enter the commands shown below. Note that I set the backend to PS and interactive to false, but my python interpreter still freezes. I suspect that this is because matplotlib is generating some GUI events which upset emacs. The example works fine if I run python through the shell without emacs, but I would very much like to run python through an emacs session. Similar problems happen with other backends. Any suggestions on how to solve this problem would be much appreciated.

Thanks,
-Emin

-------- Transcript of session follows --------------------------------------------------

Microsoft Windows XP [Version 5.1.2600]
© Copyright 1985-2001 Microsoft Corp.

C:>c:\python25\python.exe -i

c:\python25\python.exe -i
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import numpy
print numpy.version
1.0

import matplotlib, pylab
matplotlib.interactive(False)
matplotlib.use(‘PS’)
def example(size):

… pylab.hist(range(size))
… print ‘made hist of size %i’ % size
… return size

print [example(i) for i in range(10,20)]
made hist of size 10
made hist of size 11
made hist of size 12
made hist of size 13
made hist of size 14
made hist of size 15
made hist of size 16
made hist of size 17
made hist of size 18
made hist of size 19
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

python is now frozen

I'm not sure, but I guess you should make
matplotlib.interactive(False) and matplotlib.use('PS') BEFORE
importing pylab.

Nicolas Grilly

···

On 11/16/06, Emin.shopper Martinian.shopper <emin.shopper@...287...> wrote:

Whenever I try to use matplotlib from a python session inside emacs, python
freezes. What I do is start GNU Emacs version 21.1.3 for Windows, do ESC-x
shell and enter the commands shown below. Note that I set the backend to PS
and interactive to false, but my python interpreter still freezes. I suspect
that this is because matplotlib is generating some GUI events which upset
emacs. The example works fine if I run python through the shell without
emacs, but I would very much like to run python through an emacs session.
Similar problems happen with other backends. Any suggestions on how to solve
this problem would be much appreciated.

Dear Nicolas,

Thank you very much for your suggestion. I can now use matplotlib and pylab in non-interactive mode in emacs, which makes me very happy.

The only thing that would make me even happier is if I could use matplotlib/pylab in interative mode through emacs :). That’s probably a longer term issue, though.

Thanks again,
-Emin

···

On 11/27/06, Nicolas Grilly <nicolas.grilly@…1343…> wrote:

I’m not sure, but I guess you should make
matplotlib.interactive(False) and matplotlib.use
(‘PS’) BEFORE
importing pylab.

Nicolas Grilly

On 11/16/06, Emin.shopper Martinian.shopper <emin.shopper@…287…> wrote:

Whenever I try to use matplotlib from a python session inside emacs, python

freezes. What I do is start GNU Emacs version 21.1.3 for Windows, do ESC-x
shell and enter the commands shown below. Note that I set the backend to PS
and interactive to false, but my python interpreter still freezes. I suspect

that this is because matplotlib is generating some GUI events which upset
emacs. The example works fine if I run python through the shell without
emacs, but I would very much like to run python through an emacs session.

Similar problems happen with other backends. Any suggestions on how to solve
this problem would be much appreciated.