matplotlib数据可视化,绘制直方图时报错如下:
D:\python\Anaconda3\python.exeD:/python/pycharm2020/my_program/program/matplotlib/直方图/demo1.pyTraceback (mostrecentcalllast): File"D:/python/pycharm2020/my_program/program/matplotlib/直方图/demo1.py", line25, in<module>plt.hist(data, bins=40, normed=0, facecolor="blue", edgecolor="black", alpha=0.7) File"D:\python\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line2605, inhistreturngca().hist( File"D:\python\Anaconda3\lib\site-packages\matplotlib\__init__.py", line1565, ininnerreturnfunc(ax, *map(sanitize_sequence, args), **kwargs) File"D:\python\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py", line6819, inhistp.update(kwargs) File"D:\python\Anaconda3\lib\site-packages\matplotlib\artist.py", line1006, inupdateret= [_update_property(self, k, v) fork, vinprops.items()] File"D:\python\Anaconda3\lib\site-packages\matplotlib\artist.py", line1006, in<listcomp>ret= [_update_property(self, k, v) fork, vinprops.items()] File"D:\python\Anaconda3\lib\site-packages\matplotlib\artist.py", line1001, in_update_propertyraiseAttributeError('{!r} object has no property {!r}'AttributeError: 'Rectangle'objecthasnoproperty'normed'
原因:matplotlib版本问题,最新版本已经没有这个属性了。normed参数替换成 density 即可。
density=True:表示的是频率直方图
density=False:表示的是频数直方图