用频率百分比在Python中绘制直方图

时间:2020-07-16 17:08:32

标签: python matplotlib graph

我有一个要绘制直方图的等级列表。左侧(y轴)显示频率计数,是否可以根据流量显示百分比。

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.hist(item['ratings'], bins = 5)
ax.legend()
ax.set_title("Ratings Frequency")
ax.set_xlabel("Ratings")
ax.set_ylabel("frequency")
ax.axhline(y=0, linestyle='--', color='k')

1 个答案:

答案 0 :(得分:0)

您可以使用countplot尝试使用seaborn库,这将使数据可视化变得非常容易

import seaborn as sns   
sns.countplot()