python hist2d未定义

时间:2014-05-23 09:01:36

标签: python matplotlib

我想用python绘制一个二维直方图。我在matplotlib wiki上找到了以下示例

from pylab import *
x = randn(1000)
y = randn(1000)+5

#normal distribution center at x=0 and y=5
hist2d(x,y,bins=40)
show()

但我得到了错误

> Traceback (most recent call last):   File "./hist2d_demo.py", line 9,
> in <module>
>     hist2d(x,y,bins=40) NameError: name 'hist2d' is not defined

任何人都知道如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

我只是在我的python 2.7.6中对你的代码示例进行了复制,它运行得很好。 我还安装了numpy 1.8.0,scipy 0.9.0和matplotlib 1.3.0。 您的matplotlib版本可能太旧了,请按照以下方式检查:

import matplotlib
print matplotlib.__version__