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.
I think there are two ways to do it.
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.
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>]
>>>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With