你可以在一个分组中的条形之间添加空白间隔吗?

huangapple go评论82阅读模式
英文:

How can I add space between bars in a dodged (hue) group?

问题

你可以在seaborn histplot中的"shrink"参数上增加一些数值来增加男性和女性柱状图之间的间距。例如:

sns.histplot(data=tips, x="day", hue="sex", multiple="dodge", shrink=0.6)

这将增加男性和女性柱状图之间的间距。

英文:

How can I add space between Male and Female bars in seaborn histplot ?

import seaborn as sns
tips = sns.load_dataset("tips")
sns.histplot(data=tips, x="day", hue="sex", multiple="dodge", shrink=.9)
plt.show()

你可以在一个分组中的条形之间添加空白间隔吗?

答案1

得分: 4

这部分的内容翻译如下:

虽然我认为不能直接通过sns.histplot来实现这一目标,但你可以使用更灵活(尽管更复杂)的seaborn.objects接口来达到相同的效果。

对于这个具体的示例,你可以通过在条形之间留有间隔(参见seaborn.objects.Dodge)来实现相同的图形效果:

import seaborn as sns
import seaborn.objects as so
tips = sns.load_dataset("tips")
so.Plot(tips, x="day", color="sex").add(so.Bar(), so.Count(), so.Dodge(gap=0.2))

你可以在一个分组中的条形之间添加空白间隔吗?

英文:

While I don't think this can be achieved directly with sns.histplot, you could use the seaborn.objects interface, which is more flexible (at the expense of complexity).

For this specific example, here's how you could achieve the same plot, but with a gap between the bars (see seaborn.objects.Dodge):

import seaborn as sns
import seaborn.objects as so
tips = sns.load_dataset("tips")
so.Plot(tips, x="day", color="sex").add(so.Bar(), so.Count(), so.Dodge(gap=0.2))

你可以在一个分组中的条形之间添加空白间隔吗?

huangapple
  • 本文由 发表于 2023年4月10日 18:37:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75976348.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定