使用内联/嵌入图在IPython中运行python脚本

emb*_*ert 12 python inline matplotlib ipython

我想在一个带有python脚本的文件夹中有一个批处理文件.批处理文件应该调用脚本IPython并绘制内嵌/嵌入的图形.虽然有很多关于这方面的信息,但我没有让这个工作.

  • 如何运行python脚本IPython,显示嵌入的图?
  • 我需要使用pylab还是只能导入matplotlib.pyplot脚本?
  • 我是否必须适应脚本中的其他内容?
  • %pylab inline/ %matplotlib inline使用或不?

后面的命令给出了

In [1]: %pylab inline
UsageError: Invalid GUI request u'inline', valid ones are:[None, 'osx', 'qt4', 
'glut',   'gtk3', 'pyglet', 'wx', 'none', 'qt', 'gtk', 'tk']
In [2]: %matplotlib inline 
UsageError: Invalid GUI request u'inline', valid ones are:  [None, 'osx', 'qt4',
'glut', 'gtk3', 'pyglet', 'wx', 'none', 'qt', 'gtk', 'tk']`
Run Code Online (Sandbox Code Playgroud)

到目前为止我尝试了以下(不幸)

ipython --pylab=inline example_plots.py
Run Code Online (Sandbox Code Playgroud)

给我以下内容并退出

E:\CD\package\bin>ipython --pylab=inline example_plots.py
WARNING: 'inline' not available as pylab backend, using 'auto' instead.
WARNING: 'inline' not available as pylab backend, using 'auto' instead.
Run Code Online (Sandbox Code Playgroud)

或从控制台运行,但像往常一样弹出数字(并立即关闭):

E:\CD\package\bin>ipython --pylab=inline example_plots.py
WARNING: 'inline' not available as pylab backend, using 'auto' instead.
WARNING: 'inline' not available as pylab backend, using 'auto' instead.
Using matplotlib backend: Qt4Agg
# runs python script as usual (not inline)
Run Code Online (Sandbox Code Playgroud)

以下如何
使用批处理文件(与控制台相同)使IPython笔记本matplotlib图内联:

ipython notebook --pylab inline example_plots.py
2014-01-26 17:52:10.101 [NotebookApp] Using existing profile dir: u'C:\\Users\\Robert\\.ipython\\profile_default'
2014-01-26 17:52:10.111 [NotebookApp] Using MathJax from CDN: http://cdn.mathjax.org/mathjax/latest/MathJax.js
2014-01-26 17:52:10.127 [NotebookApp] Serving notebooks from local directory: E:\CD\package\bin
2014-01-26 17:52:10.128 [NotebookApp] The IPython Notebook is running at: http://127.0.0.1:8888/
2014-01-26 17:52:10.128 [NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
Run Code Online (Sandbox Code Playgroud)

打开一个空的笔记本就可以了.

我还应该尝试什么?

Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)]
IPython 1.1.0 -- An enhanced Interactive Python.
Run Code Online (Sandbox Code Playgroud)

emb*_*ert 8

Greg在这里回答:
在脚本执行后启动ipython qtconsole作为交互式解释器

它使用-m标志

ipython qtconsole --matplotlib inline -m example_plots
Run Code Online (Sandbox Code Playgroud)

要么

ipython qtconsole --pylab inline -m example_plots
Run Code Online (Sandbox Code Playgroud)

但我不知道,是什么让这两个选项之间的差异pylab inlinematplotlib inline.从这里我想,我宁愿使用--matplotlib inline

即使添加结束它的文件也能做到我想要的,但它unknown failure在执行后会抱怨.

pyplot.show(block=True)将给予和unknown failure,太