【问题标题】:centre palette for plotting - Seaborn用于绘图的中心调色板 - Seaborn
【发布时间】:2020-07-14 06:58:15
【问题描述】:

我希望使用转移色彩图将 seaborn 调色板居中。具体来说,我希望零表示分歧。但是,可能值分布不均。所以最小值和最大值与 0 的距离不同。因此,调色板没有对齐。我仍然希望使用相同的调色板颜色,但将分歧集中在 0。

df = pd.DataFrame({ 
    'Val' : ['A','A','A','A','A','A','A','A','A','A','A','A'],                  
    'A_1' : [-5, 2, 3, 4, 5, 7, 1, -4, -2, 6, -1, 0],                      
        })

g = sns.FacetGrid(df, 
                  col = 'Val', 
                  hue = 'A_1',                               
                  aspect = 1,
                  height = 5, 
                  palette = 'BrBG',
                  sharex = False)


g.map(sns.swarmplot, 'Val', 'A_1')

【问题讨论】:

    标签: pandas seaborn palette


    【解决方案1】:

    很遗憾,您不能直接这样做。

    有一种解决方法应该可以正常工作:seaborn's diverging palette

    它允许您创建您选择的调色板。您可以选择以与您想要的完全匹配的方式定位颜色。

    文档中的示例非常好。另一个很好的例子:

    Seaborn color palette: how to choose which part to center on (e.g. which end of the plot is red and which end is blue)?

    Creating a diverging color palette with a “midrange” instead of a “midpoint”

    【讨论】:

      猜你喜欢
      • 2019-01-16
      • 2020-12-16
      • 1970-01-01
      • 1970-01-01
      • 2016-06-04
      • 2021-09-16
      • 2021-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多