gpt4 book ai didi

python - 类型错误 : histogram() got an unexpected keyword argument 'new'

转载 作者:太空狗 更新时间:2023-10-30 00:14:11 24 4
gpt4 key购买 nike

我很难尝试在 mac osx 上使用 python、numpy 和 matplotlib 绘制直方图。我在 6 个月前完美地运行了这个但是相同的代码产生了这个错误:

In [1]: %matplotlib inline

In [2]:import numpy as np
from numpy.random import randn
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
from scipy import stats

data = randn(75)
plt.hist(data)

返回以下信息:

    ---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-2-fa104aadeee7> in <module>()
8
9 data = randn(75)
---> 10 plt.hist(data,bins=20, density=True)

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/pyplot.pyc in hist(x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, hold, **kwargs)
2339 ax.hold(hold)
2340 try:
-> 2341 ret = ax.hist(x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, **kwargs)
2342 draw_if_interactive()
2343 finally:

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.pyc in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, **kwargs)
7734 # this will automatically overwrite bins,
7735 # so that each histogram uses the same bins
-> 7736 m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs)
7737 if normed:
7738 db = np.diff(bins)

TypeError: histogram() got an unexpected keyword argument 'new''

我尝试卸载并重新安装 python、ipython、numpy、matplotlib 和 scipy,并将它们安装在 /usr/local/bin 中,但错误仍然存​​在。

有没有人以前见过这个问题或者知道可能的解决方案?谢谢

最佳答案

对我来说,cphlewis 的评论是我需要的提示。我当时使用的是 matplotlib 1.1,在更新到 1.5 后一切正常。

关于python - 类型错误 : histogram() got an unexpected keyword argument 'new' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29842264/

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