1

在 Seaborn 中,我希望定义在使用闪避功能时呈现色调变量的顺序。

seaborn swarmplot 文档文档为例,在解释闪避的图中,左侧显示吸烟者(绿色),右侧显示非吸烟者(橙色)。我怎样才能控制这个顺序?我想左边是非吸烟者,右边是吸烟者。

示例代码未指定并且似乎将其保留为数据格式:

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

1 回答 1

2

您可以使用参数hue_order

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

在此处输入图像描述

请注意,这不会交换颜色。

于 2018-11-02T16:16:27.360 回答