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

标签 python macos numpy matplotlib

我很难尝试在 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/

相关文章:

python - 我只想从测试文件中删除一个搜索行

objective-c - 自动调整包装 NSTextView 的 NSScrollView 大小

macos - Mac OS上正在运行的进程的工作目录

python - 使用 cv2 在 python 中创建多 channel 零垫

Python在短语列表中查找单词出现并将单词链接到短语

python - 什么控制 Tkinter 中的自动窗口大小调整?

python - Mac 和 Linux 中 lxml.etree.tostring() 中的缩进有所不同

python - 在公差范围内查找 Python 中两个矩阵的交集?

python - Pandas DataFrame 根据条件删除 NaN 行?

python - 返回默认值