plot()在IPython笔记本上不起作用 [英] plot() doesn't work on IPython notebook
问题描述
我是python科学计算的新手,我试图在IPython笔记本上制作一个简单的图形。
I'm new to python scientific computing, and I tried to make a simple graph on IPython notebook.
import pandas
plot(arange(10))
然后错误显示如下。
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-2-6b139d572bd6> in <module>()
1 import pandas
----> 2 plot(arange(10))
NameError: name 'plot' is not defined
相反,使用IPython --pylab模式,当我尝试相同的代码时会弹出一个正确的图形。
Instead, with IPython --pylab mode, a right graph popped up when I tried the same code.
我是否遗漏了任何环境?
Am I missing any environment?
我的环境是Mac OSX 10.8.5,python 2.7.5,IPython 1.1.0,matplotlib 1.3.1和pandas 0.12.0。我从Continum.io下载了Anaconda安装程序的python科学环境。 Anaconda版本是截至2014年1月30日的最新版本。
My environment is Mac OSX 10.8.5, python 2.7.5, IPython 1.1.0, matplotlib 1.3.1, and pandas 0.12.0. I downloaded python scientific environment by Anaconda installer from continuum.io. Anaconda version is the newest one as of 1/30/2014.
推荐答案
不建议使用 pylab
模式。请参阅以下发布 a href =https://twitter.com/Mbussonn> Matthias Bussonnier
It is not advisable to use pylab
mode. See the following post from Matthias Bussonnier
该帖子摘要:
为什么不使用 pylab
flag:
Why not to use pylab
flag:
- 它是不可逆转的 - 不能无关紧要
- 不清楚 - 如果其他人没有使用此标志运行(或使用不同的设置)会发生什么情况?
- 污染命名空间
- 替换内置插件
- 副作用
- It is irreversible- Cannot unimport
- Unclear- if someone else did not run with this flag (or with a different setting of it) what would happen?
- Pollutes the namespace
- Replaces built-ins
- Side effects
在IPython笔记本中进行以下操作会更好。
You are much better by doing the following inside your IPython notebook.
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot(range(10))
以下是<$的代码c $ c> - pylab 带入命名空间
import numpy
import matplotlib
from matplotlib import pylab, mlab, pyplot
np = numpy
plt = pyplot
from IPython.core.pylabtools import figsize, getfigs
from pylab import *
from numpy import *
如果你想使用 pylab
并且内联图,您可以执行以下任一操作:
Still, if you wish to use pylab
and have plots inline, you may do either of the following:
来自shell:
$ ipython notebook --pylab inline
或者,从你的笔记本中
%pylab inline
这篇关于plot()在IPython笔记本上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!