TypeError:未找到histogram weights属性或关键字参数

时间:2017-12-15 18:22:47

标签: python numpy matplotlib histogram keyword

我试图使用"权重"来制作直方图。属性或关键字参数。然而,虽然它在过去有效并且出现在帮助描述中,但现在它偶尔会失败(见下文)。我尝试安装和卸载anaconda,但它保持相同的行为。我还将程序从具有自己的pythons任务的应用程序中移出(casa.nrao.edu)。

我正在研究macOS 10.13.1(我想知道从10.12升级到10.13是否是主要问题)。我使用的是python 2.7.14,matplotlib v2.1.1,numpy 1.13.3,ipython 5.4.1(但在标准的python shell中也一样)。

import numpy as np
import matplotlib.pylab as plt

tmp=np.array([1,3,5,2])
wgt=tmp*0+1

np.histogram(tmp,weigths=wgt)
# TypeError                                 Traceback (most recent call last)
# <ipython-input-4-43a11ec135ae> in <module>()
# ----> 1 np.histogram(tmp,weigths=wgt)
# TypeError: histogram() got an unexpected keyword argument 'weigths'

plt.hist(tmp,weigths=wgt)
# ...
# /Users/hugomessias/anaconda2/lib/python2.7/site-packages/matplotlib/pyplot.pyc in hist(x, bins, range, density, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, normed, hold, data, **kwargs)
# 3023                       histtype=histtype, align=align, orientation=orientation,
# 3024                       rwidth=rwidth, log=log, color=color, label=label,
# -> 3025                       stacked=stacked, normed=normed, data=data, **kwargs)
# ...
# /Users/hugomessias/anaconda2/lib/python2.7/site-packages/matplotlib/__init__.pyc in inner(ax, *args, **kwargs)
# 1715                     warnings.warn(msg % (label_namer, func.__name__),
# 1716                                   RuntimeWarning, stacklevel=2)
# -> 1717             return func(ax, *args, **kwargs)
# ...
# /Users/hugomessias/anaconda2/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in hist(***failed resolving arguments***)
# 6347             if patch:
# 6348                 p = patch[0]
# -> 6349                 p.update(kwargs)
# ...
# /Users/hugomessias/anaconda2/lib/python2.7/site-packages/matplotlib/artist.pyc in update(self, props)
# 900         try:
# 901             ret = [_update_property(self, k, v)
# --> 902                    for k, v in props.items()]
# ...
# /Users/hugomessias/anaconda2/lib/python2.7/site-packages/matplotlib/artist.pyc in _update_property(self, k, v)
# 893                 func = getattr(self, 'set_' + k, None)
# 894                 if not callable(func):
# --> 895                     raise AttributeError('Unknown property %s' % k)
# ...
# AttributeError: Unknown property weigths

f = plt.figure()
ax2 = f.add_subplot(111)
ax2.hist(tmp,weigths=wgt)
# ...
# /Users/hugomessias/anaconda2/lib/python2.7/site-packages/matplotlib/__init__.pyc in inner(ax, *args, **kwargs)
# 1715                     warnings.warn(msg % (label_namer, func.__name__),
# 1716                                   RuntimeWarning, stacklevel=2)
# -> 1717             return func(ax, *args, **kwargs)
# ...
# /Users/hugomessias/anaconda2/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in hist(***failed resolving arguments***)
# 6347             if patch:
# 6348                 p = patch[0]
# -> 6349                 p.update(kwargs)
# ...
# /Users/hugomessias/anaconda2/lib/python2.7/site-packages/matplotlib/artist.pyc in update(self, props)
# 900         try:
# 901             ret = [_update_property(self, k, v)
# --> 902                    for k, v in props.items()]
# ...
# /Users/hugomessias/anaconda2/lib/python2.7/site-packages/matplotlib/artist.pyc in _update_property(self, k, v)
# 893                 func = getattr(self, 'set_' + k, None)
# 894                 if not callable(func):
# --> 895                     raise AttributeError('Unknown property %s' % k)
# ...
# Unknown property weigths

但是,偶尔,np.histogram和plt.hist确实有效,但不是ax.plot。

任何指导都会非常有用!提前谢谢!

0 个答案:

没有答案