gpt4 book ai didi

python hist2d 未定义

转载 作者:太空宇宙 更新时间:2023-11-03 18:22:39 26 4
gpt4 key购买 nike

我想用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

有人知道我该如何解决这个问题吗?

最佳答案

我刚刚将您的代码示例复制粘贴到我的 python 2.7.6 中,它运行得很好。我还安装了 numpy 1.8.0、scipy 0.9.0 和 matplotlib 1.3.0。您的 matplotlib 版本可能太旧,请按以下方式检查:

import matplotlib
print matplotlib.__version__

关于python hist2d 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23825019/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com