繁体   English   中英

TypeError:histogram()得到了意外的关键字参数“ new”

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

我在尝试在Mac OS X上使用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尽管错误仍然存​​在。

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

对我来说,cplewis的评论是我需要的提示。 我使用的是matplotlib 1.1,更新到1.5后,一切对我来说都很好。

在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

这似乎对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM