【问题标题】:Add STD to legend in python seaborn在 python seaborn 中将 STD 添加到图例
【发布时间】:2020-03-04 12:47:20
【问题描述】:

我有下面的图表,我想在图例中为每个班级添加 STD。

它是用代码创建的:

subset1=data1[feats_to_explore+['wine_class']]
f, (ax1, ax2, ax3) = plt.subplots(3, figsize=(7,14), sharey=True)

l=[ax1,ax2,ax3]
colors=['lime','deeppink','dodgerblue']

## La única modificación se da en la incorporación de la línea vertical con las medias.
for graph in l:
    for i in (subset1['wine_class']).unique():
        df =subset1[subset1.wine_class == i]
        sns.distplot(df[feats_to_explore[l.index(graph)]],  kde=False, label=i, ax=graph, color=colors[int(i)])
        graph.axvline(df[feats_to_explore[l.index(graph)]].mean(),color=colors[int(i)])  
        graph.legend(title='Wine Class')

我想在标记(0.0、1.0 或 2.0)的右侧添加每个组的标准。有人可以在这个问题上支持我吗?

问候,

【问题讨论】:

    标签: python histogram data-visualization seaborn legend


    【解决方案1】:

    我终于找到了解决方案。如果有人需要,我会在以下几行中向您介绍:

    tipo=['Class 0','Class 1','Class 2']
    for graph in l:
        w=[str(x) for x in np.around((subset1.groupby('wine_class').std()[feats_to_explore[l.index(graph)]]).to_numpy(),decimals=2)]
        for i in (subset1['wine_class']).unique():
            df =subset1[subset1.wine_class == i]
            sns.distplot(df[feats_to_explore[l.index(graph)]],  kde=False, label=i, ax=graph, color=colors[int(i)])
            graph.axvline(df[feats_to_explore[l.index(graph)]].mean(),color=colors[int(i)])  
            graph.legend([str(tipo[i]) +": "+ str(w[i]) for i in range(len(tipo))],title='wine_class')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-24
      • 1970-01-01
      • 1970-01-01
      • 2020-09-16
      • 2021-11-20
      • 1970-01-01
      • 2019-04-15
      • 2015-08-10
      相关资源
      最近更新 更多