[英]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:例子:
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.