【问题标题】:Add mean line in Seaborn plot [duplicate]在 Seaborn 图中添加平均线 [重复]
【发布时间】:2022-06-11 01:11:49
【问题描述】:

我想在 sns 图中添加一条“DP 入口”的平均线。我该如何管理?

g=sns.relplot(x="TimeStamp", y="DP Inlet", hue="humidity", data=df).set(title='DP inlet over time vs Temp')

sns.set(font_scale = 1)

g.fig.set_figwidth(30.27)
g.fig.set_figheight(20.7)

输出图:

【问题讨论】:

    标签: python matplotlib seaborn


    【解决方案1】:

    由于没有提供数据来重现图像,我使用 Seaborn 中提供的数据集来帮助解决这个问题:

    import matplotlib.pyplot as plt 
    import seaborn as sns 
    
    tips = sns.load_dataset("tips")
    g = sns.relplot(data=tips, x="total_bill", y="tip", hue="day")
    
    def specs(x, **kwargs):
        plt.axhline(x.mean(), c='k', ls='-', lw=2.5)
    
    g.map(specs, 'tip')
    plt.show()
    

    这给出了:

    更详细的解决方案,请查看How to add a mean and median line to a Seaborn displot。我在同一篇文章中使用了this answer 来为绘图添加平均线。

    【讨论】:

      猜你喜欢
      • 2019-01-21
      • 2021-08-09
      • 2021-08-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-31
      • 2017-12-04
      • 1970-01-01
      相关资源
      最近更新 更多