gpt4 book ai didi

python - 使用 hue 参数在 seaborn 中拆分 fiddle 图

转载 作者:太空狗 更新时间:2023-10-29 20:12:17 25 4
gpt4 key购买 nike

我正在尝试仅使用 seaborn 中的 yhue 参数制作一个 violinplot(x 数据变量定义为无)。使用与我完成的文档中类似的示例:

tips = sns.load_dataset("tips")
sns.violinplot(y="total_bill", hue="sex", data=tips, split=True)

并且生成的图形不会根据 hue 变量进行分割。

enter image description here

当定义了 x 变量时,绘图被拆分。有什么方法可以在没有 x 输入的情况下在 seaborn 中生成分割图?

最佳答案

只需添加一个对所有条目都相同的变量并将其用作x:

tips = sns.load_dataset("tips")
tips["all"] = ""
ax = sns.violinplot(x="all", y="total_bill", hue="sex", data=tips, split=True)
ax.set_xlabel("")

enter image description here

关于python - 使用 hue 参数在 seaborn 中拆分 fiddle 图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33745746/

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