回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我想在一个文件夹中有一个带有<code>python</code>脚本的批处理文件。批处理文件应该调用<code>IPython</code>中的脚本,并以内联/嵌入式方式绘制图形。虽然有很多关于这方面的信息,但我没能让它发挥作用。</p>
<ul>
<li>如何使用<code>IPython</code>运行<code>python</code>脚本,显示嵌入的绘图?</strong></li>
<li>我需要使用<code>pylab</code>还是只需在脚本中导入<code>matplotlib.pyplot</code>?</li>
<li>我还需要改编剧本吗?</li>
<li>是否使用<code>%pylab inline</code>/<code>%matplotlib inline</code>?</li>
</ul>
<p>后一个命令给出</p>
<pre><code>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']`
</code></pre>
<p>到目前为止,我试着做了以下事情(不走运)</p>
<pre><code>ipython --pylab=inline example_plots.py
</code></pre>
<p>给我下面的,然后退出</p>
<pre><code>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.
</code></pre>
<p>或者从控制台运行,但像往常一样弹出数字(并立即关闭):</p>
<pre><code>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)
</code></pre>
<p>跟随<a href="https://stackoverflow.com/questions/19410042/how-to-make-ipython-notebook-inline-matplotlib-graphics">How to make IPython notebook matplotlib plot inline</a><br/>
对于批处理文件(与控制台相同):</p>
<pre><code>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).
</code></pre>
<p>打开一个空笔记本,就这样。</p>
<p>我还应该尝试什么?</p>
<pre><code>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.
</code></pre>