matplotlib数据可视化,绘制直方图时报错如下:
代码语言:javascript复制D:pythonAnaconda3python.exe D:/python/pycharm2020/my_program/program/matplotlib/直方图/demo1.py
Traceback (most recent call last):
File "D:/python/pycharm2020/my_program/program/matplotlib/直方图/demo1.py", line 25, in <module>
plt.hist(data, bins=40, normed=0, facecolor="blue", edgecolor="black", alpha=0.7)
File "D:pythonAnaconda3libsite-packagesmatplotlibpyplot.py", line 2605, in hist
return gca().hist(
File "D:pythonAnaconda3libsite-packagesmatplotlib__init__.py", line 1565, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File "D:pythonAnaconda3libsite-packagesmatplotlibaxes_axes.py", line 6819, in hist
p.update(kwargs)
File "D:pythonAnaconda3libsite-packagesmatplotlibartist.py", line 1006, in update
ret = [_update_property(self, k, v) for k, v in props.items()]
File "D:pythonAnaconda3libsite-packagesmatplotlibartist.py", line 1006, in <listcomp>
ret = [_update_property(self, k, v) for k, v in props.items()]
File "D:pythonAnaconda3libsite-packagesmatplotlibartist.py", line 1001, in _update_property
raise AttributeError('{!r} object has no property {!r}'
AttributeError: 'Rectangle' object has no property 'normed'
原因:matplotlib版本问题,最新版本已经没有这个属性了。normed参数替换成 density 即可。
density=True:表示的是频率直方图
density=False:表示的是频数直方图