TypeError:histogram()得到一个意外的关键字参数'new'

时间:2015-04-24 08:22:36

标签: 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中安装它们,尽管错误仍然存​​在。

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

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

在OSX中,我不得不手动删除matplotlib库:rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib

然后我卸载了matplotlib:sudo pip uninstall matplotlib 我重新安装了matplotlibsudo pip install matplotlib==1.5.1

这似乎对我有用。