报错:
我遇到的问题:Traceback (most recent call last):
File "D:\pythonProject4\2.87.py", line 7, in <module>
plt.hist(data,bins = 40,normed = 0,facecolor = "c",edgecolor="black",alpha=1)
File "D:\pythonProject4\venv\lib\site-packages\matplotlib\pyplot.py", line 3224, in hist
return gca().hist(
File "D:\pythonProject4\venv\lib\site-packages\matplotlib_init_.py", line 1492, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File "D:\pythonProject4\venv\lib\site-packages\matplotlib\axes_axes.py", line 7012, in hist
p._internal_update(kwargs)
File "D:\pythonProject4\venv\lib\site-packages\matplotlib\artist.py", line 1219, in _internal_update
return self._update_props(
File "D:\pythonProject4\venv\lib\site-packages\matplotlib\artist.py", line 1193, in _update_props
raise AttributeError(
AttributeError: Rectangle.set() got an unexpected keyword argument 'normed'
源代码:
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
matplotlib.rcParams['axes.unicode_minus'] = False
data = np.random.randn(500)
plt.hist(data,bins = 40, normed = 0,facecolor = "c",edgecolor="black",alpha=1)
plt.xlabel("区间")
plt.ylabel("频率")
plt.title('Histogram',fontsize = 'large',fontweight = 'bold',color = 'blue')
plt.show()
其中的plt.hist(data,bins = 40, **normed = 0 **,facecolor = “c”,edgecolor=“black”,alpha=1)
(normed=0)
不适用新版本的pycharm。
应该修改成
(density=0)
plt.hist(data,bins = 40,density = 0,facecolor = “c”,edgecolor=“black”,alpha=1)
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
matplotlib.rcParams['axes.unicode_minus'] = False
data = np.random.randn(500)
plt.hist(data,bins = 40,density = 0,facecolor = "c",edgecolor="black",alpha=1)
plt.xlabel("区间")
plt.ylabel("频率")
plt.title('Histogram',fontsize = 'large',fontweight = 'bold',color = 'blue')
plt.show()
运行成功: