【问题标题】:map the colors of a boxplot with values using seaborn使用 seaborn 将箱线图的颜色与值映射
【发布时间】:2020-12-05 00:32:45
【问题描述】:

我正在根据某些值制作带有 seaborn 的箱线图,并且我想将颜色与我正在执行的其他颜色映射:

plt.figure(figsize=(20,12))
sns.boxplot(y='name',x='value',data=df,showfliers=False,orient="h")

结果是带有随机颜色的箱线图,我希望根据数据框中第三列的值来定义颜色。我唯一能找到的就是使用“HUE”,但它会将数据划分到更多箱线图上,这不是我想要做的

【问题讨论】:

    标签: pandas dataframe charts colors seaborn


    【解决方案1】:

    你确实可以用hue指定颜色:

    sns.boxplot(x='name', y='value', data=df
                hue='name',     # same with `x`
                palette={'A':'r','B':'b'},  # specify color
                )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-03
      • 2023-03-29
      • 2016-02-06
      • 2020-08-28
      • 1970-01-01
      • 2020-08-07
      • 1970-01-01
      • 2019-03-03
      相关资源
      最近更新 更多