簡體   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