plot()在IPython笔记本上不起作用 [英] plot() doesn't work on IPython notebook

查看:301
本文介绍了plot()在IPython笔记本上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是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:


  1. 它是不可逆转的 - 不能无关紧要

  2. 不清楚 - 如果其他人没有使用此标志运行(或使用不同的设置)会发生什么情况?

  3. 污染命名空间

  4. 替换内置插件

  5. 副作用

  1. It is irreversible- Cannot unimport
  2. Unclear- if someone else did not run with this flag (or with a different setting of it) what would happen?
  3. Pollutes the namespace
  4. Replaces built-ins
  5. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆