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

查看:64
本文介绍了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.

我缺少任何环境吗?

我的环境是Mac OSX 10.8.5,python 2.7.5,IPython 1.1.0,matplotlib 1.3.1和pandas 0.12.0.我从continuum.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 标志:

  1. 这是不可逆的-无法取消导入
  2. 不清楚-如果其他人未使用此标志(或使用其不同的设置)运行,会发生什么情况?
  3. 污染名称空间
  4. 替换内置
  5. 副作用

通过在IPython笔记本中执行以下操作,您会变得更好.

You are much better by doing the following inside your IPython notebook.


%matplotlib inline

import matplotlib.pyplot as plt
plt.plot(range(10))

以下是-pylab 带入名称空间的代码

The following is the code which --pylab brings into the namespace


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天全站免登陆