gpt4 book ai didi

python - 如何在 Seaborn 中禁用色调制作的嵌套?

转载 作者:行者123 更新时间:2023-12-04 09:10:07 24 4
gpt4 key购买 nike

使用时 hue Seaborn 中条形图上的参数会改变条形的颜色和位置。像下面的例子:
无色相图:

import seaborn as sns
df = {'x': [1, 2, 3, 4], 'y': [5, 6, 7, 8], 'hue': ['a', 'b', 'b', 'a']}
sns.barplot(
data = df,
x = 'x',
y = 'y',
)
输出:
Seaborn barplot without hue
用色调绘图:
df = {'x': [1, 2, 3, 4], 'y': [5, 6, 7, 8], 'hue': ['a', 'b', 'b', 'a']}
sns.barplot(
data = df,
x = 'x',
y = 'y',
hue = 'hue'
)
输出:
Seaborn barplot with hue
那么我怎样才能用默认的条形位置和由 hue 制作的颜色绘制一个图? ?

最佳答案

设置 dodge=False为我修复它。

import seaborn as sns

df = {'x': [1, 2, 3, 4], 'y': [5, 6, 7, 8], 'hue': ['a', 'b', 'b', 'a']}
sns.barplot(
data = df,
x = 'x',
y = 'y',
hue = 'hue',
dodge=False
)
来自 docs :

dodge (bool, optional) - When hue nesting is used, whether elementsshould be shifted along the categorical axis.

关于python - 如何在 Seaborn 中禁用色调制作的嵌套?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63365569/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com