【问题标题】:Plotting histogram in Python with frequency percentage在 Python 中使用频率百分比绘制直方图
【发布时间】:2020-07-16 17:08:32
【问题描述】:

我有一个评分列表,我正在为其绘制直方图。在左侧(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')

【问题讨论】:

    标签: python matplotlib graph


    【解决方案1】:

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

    import seaborn as sns   
    sns.countplot()
    

    【讨论】:

    • 谢谢,但这是一个我们只能使用 matplotlib 的作业。
    猜你喜欢
    • 2017-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-11
    • 2015-05-10
    • 2016-02-10
    • 1970-01-01
    • 2016-06-12
    相关资源
    最近更新 更多