我对python和计算机科学一般都很陌生,所以也许我错过了一些明显的东西,但如果有人能说出来,我会非常感激! 我无法弄清楚我的pyplot直方图功能发生了什么 独立于列表,它被要求绘制它返回属性错误。有谁知道我怎么解决这个问题?
运行时:
import matplotlib.pyplot as plt
import numpy as np
test = [np.random.randn() for i in range(100)]
plt.hist(test)
plt.show()
它返回:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-268-b26700f187c9> in <module>()
5 test = [np.random.randn() for i in range(10**3)]
6
----> 7 plt.hist(test)
8 plt.show()
c:\users\wiepvandertoorn\appdata\local\programs\python\python36\lib\site-packages\matplotlib\pyplot.py in hist(x, bins, range, density, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, normed, hold, data, **kwargs)
3002 histtype=histtype, align=align, orientation=orientation,
3003 rwidth=rwidth, log=log, color=color, label=label,
-> 3004 stacked=stacked, normed=normed, data=data, **kwargs)
3005 finally:
3006 ax._hold = washold
c:\users\wiepvandertoorn\appdata\local\programs\python\python36\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
1708 warnings.warn(msg % (label_namer, func.__name__),
1709 RuntimeWarning, stacklevel=2)
-> 1710 return func(ax, *args, **kwargs)
1711 pre_doc = inner.__doc__
1712 if pre_doc is None:
c:\users\wiepvandertoorn\appdata\local\programs\python\python36\lib\site-packages\matplotlib\axes\_axes.py in hist(***failed resolving arguments***)
6284 patch = _barfunc(bins[:-1]+boffset, height, width,
6285 align='center', log=log,
-> 6286 color=c, **{bottom_kwarg: bottom})
6287 patches.append(patch)
6288 if stacked:
c:\users\wiepvandertoorn\appdata\local\programs\python\python36\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
1708 warnings.warn(msg % (label_namer, func.__name__),
1709 RuntimeWarning, stacklevel=2)
-> 1710 return func(ax, *args, **kwargs)
1711 pre_doc = inner.__doc__
1712 if pre_doc is None:
c:\users\wiepvandertoorn\appdata\local\programs\python\python36\lib\site-packages\matplotlib\axes\_axes.py in bar(self, *args, **kwargs)
2118
2119 if self.yaxis is not None:
-> 2120 y = self.convert_yunits(y)
2121 height = self.convert_yunits(height)
2122 if yerr is not None:
c:\users\wiepvandertoorn\appdata\local\programs\python\python36\lib\site-packages\matplotlib\artist.py in convert_yunits(self, y)
198 if ax is None or ax.yaxis is None:
199 return y
--> 200 return ax.yaxis.convert_units(y)
201
202 @property
c:\users\wiepvandertoorn\appdata\local\programs\python\python36\lib\site-packages\matplotlib\axis.py in convert_units(self, x)
1489 return x
1490
-> 1491 ret = self.converter.convert(x, self.units, self)
1492 return ret
1493
c:\users\wiepvandertoorn\appdata\local\programs\python\python36\lib\site-packages\matplotlib\category.py in convert(value, unit, axis)
41 data as floats
42 """
---> 43 vmap = dict(zip(axis.unit_data.seq, axis.unit_data.locs))
44
45 if isinstance(value, six.string_types):
AttributeError: 'NoneType' object has no attribute 'seq'