我想在一个带有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']`
到目前为止,我尝试了以下(不幸的)
ipython --pylab=inline example_plots.py
给我以下内容并退出
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.
或从控制台运行,但像往常一样弹出数字(并立即关闭):
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)
关注How to make IPython notebook matplotlib plot inline
使用批处理文件(和控制台一样):
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).
打开一个空的笔记本就可以了。
我还应该尝试什么?
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.
答案 0 :(得分:7)
使用-m
标志
ipython qtconsole --matplotlib inline -m example_plots
或
ipython qtconsole --pylab inline -m example_plots
但我不知道,这两个选项pylab inline
和matplotlib inline
之间的区别是什么。从here开始,我想,我宁愿使用--matplotlib inline
即使添加结束它的文件也可以执行我想要的操作,但是在执行后它会抱怨unknown failure
。
pyplot.show(block=True)
也会提供unknown failure
答案 1 :(得分:2)
如何使用IPython运行python脚本,显示嵌入的图?
ipython qtconsole <yourscript.py>
。jupyter qtconsole <yourscript.py>
我是否需要使用pylab或者我可以在脚本中导入matplotlib.pyplot吗?
%matplotlib inline
。是否使用%pylab内联/%matplotlib内联?
%matplotlib inline
。