Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs Python-inferior shell not showing prompt after matplotlib show() command

So I've been experimenting with numpy and matplotlib and have stumbled across some bug when running python from the emacs inferior shell.

When I send the py file to the shell interpreter I can run commands after the code executed. The command prompt ">>>" appears fine. However, after I invoke a matplotlib show command on a plot the shell just hangs with the command prompt not showing.

>>> plt.plot(x,u_k[1,:]);
[<matplotlib.lines.Line2D object at 0x0000000004A9A358>]
>>> plt.show();

I am running the traditional C-python implementation. under emacs 23.3 with Fabian Gallina's Python python.el v. 0.23.1 on Win7.

A similar question has been raised here under the i-python platform: running matplotlib or enthought.mayavi.mlab from a py-shell inside emacs on windows

UPDATE: I have duplicated the problem on a fresh instalation of Win 7 x64 with the typical python 2.7.2 binaries available from the python website and with numpy 1.6.1 and matplotlib 1.1.0 on emacs 23.3 and 23.4 for Windows.

There must be a bug somewhere in the emacs shell.

like image 947
octi Avatar asked Feb 01 '12 19:02

octi


2 Answers

I think there are two ways to do it.

  1. Use ipython. Then you can use -pylab option. I don't use Fabian Gallina's python.el, but I guess you will need something like this:

    (setq python-shell-interpreter-args "-pylab")
    

    Please read the documentation of python.el.

  2. You can manually activate interactive mode by ion

    >>> from matplotlib import pyplot as plt
    >>> plt.ion()
    >>> plt.plot([1,2,3])
    [<matplotlib.lines.Line2D object at 0x20711d0>]
    >>>
    
like image 53
tkf Avatar answered Sep 19 '22 18:09

tkf


You can use different back-end:

matplotlib.use('TkAgg')
import matplotlib.pyplot as plt 

Other GUI backends:

  • TkAgg
  • WX
  • QTAgg
  • QT4Agg

If you are using Elpy run your code using C-u C-c C-c

like image 44
Mahyar Avatar answered Sep 19 '22 18:09

Mahyar