简体   繁体   English

对 seaborn swarmplot 中的各个点进行排序

[英]Sorting individual points in seaborn swarmplot

Is there a way to change the order of the individual dots in a seaborn swarmplot within the categories?有没有办法改变类别中 seaborn swarmplot 中各个点的顺序? That is, I would like to sort them so that all points of the same color are bunched together and we can group them in the order blue/orange/green.也就是说,我想对它们进行排序,以便将所有相同颜色的点聚集在一起,我们可以按蓝色/橙色/绿色的顺序对它们进行分组。

Example:例子:

  • In the figure below, Male/Thursday has: orange/blue/green/blue.下图中,Male/Thursday 有:orange/blue/green/blue。
  • Can we sort the points so that they appear as blue/blue/orange/green?我们可以对点进行排序,使它们显示为蓝色/蓝色/橙色/绿色吗?
import seaborn as sns
# Load data
tips = sns.load_dataset("tips")

# Simplify the data
df = tips.loc[tips["size"] > 3]

# Plot
sns.swarmplot(data=df, x="sex", y="day", hue="size", size = 8) 

在此处输入图像描述

You could use dodge as the docs say:你可以使用dodge作为文档说:

By default, the different levels of the hue variable are intermingled in each swarm, but setting dodge=True will split them:默认情况下,不同级别的 hue 变量在每个 swarm 中混合在一起,但设置 dodge=True 会拆分它们:

import seaborn as sns
# Load data
tips = sns.load_dataset("tips")

# Simplify the data
df = tips.loc[tips["size"] > 3]

# Plot
sns.swarmplot(data=df, x="sex", y="day", hue="size", size = 8, dodge=True) 

在此处输入图像描述

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

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