简体   繁体   English

闪避的Python Seaborn swarmplot顺序

[英]Python Seaborn swarmplot order of the dodge

In Seaborn, I am looking to define the order in which the hue variables are presented when using the dodge functionality.在 Seaborn 中,我希望定义使用闪避功能时色调变量的显示顺序。

Using the seaborn swarmplot documentation documentation as an example, in the plot where dodge is explained, they show smoker (green) on the left and non-smoker (orange) on the right.seaborn swarmplot 文档文档为例,在解释 dodge 的图中,它们在左侧显示吸烟者(绿色),在右侧显示非吸烟者(橙色)。 How can I control that order?我怎样才能控制那个顺序? I would like non-smoker on the left and smoker on the right.我想左边不抽烟,右边抽烟。

The example code does not specify and seems to leave it up to the format of the data:示例代码没有指定,似乎让它取决于数据的格式:

ax = sns.swarmplot(x="day", y="total_bill", hue="smoker", data=tips, palette="Set2", dodge=True)

You can use the argument hue_order :您可以使用参数hue_order

ax = sns.swarmplot(x="day", y="total_bill", hue="smoker", hue_order=["No", "Yes"], 
                    data=tips, palette="Set2", dodge=True)

在此处输入图片说明

Note that this does not swap the colours around.请注意,这不会交换周围的颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM