简体   繁体   English

使用 seaborn.FacetGrid 时如何更改 X 轴上的分类值的顺序?

[英]how to change the order of categorical values on X-axis when using seaborn.FacetGrid?

I have following code:我有以下代码:

g = sns.FacetGrid(correct_data, hue="congruency", col="PP", row="cue", height=4, ylim=(.4, .9))
g.map(sns.pointplot, "pattern", "RT")

This allows me to create a line plot per participant (PP) and cue (cue) showing separate lines for each level of congruency.这使我可以为每个参与者 (PP) 和提示 (cue) 创建一条线 plot,并为每个一致性级别显示单独的线。 Each line shows the relationship between pattern (X-axis) and reaction time (RT on the Y-axis).每条线显示模式(X 轴)和反应时间(Y 轴上的 RT)之间的关系。 I would like the reverse the order of the categorical values on the X-axis, how can I do this?我想反转 X 轴上分类值的顺序,我该怎么做? The "pattern"-variable has two levels, but I like to reverse the default order in which it is displayed. “模式”变量有两个级别,但我喜欢颠倒它的默认显示顺序。

Thank you.谢谢你。

You can pass the order= parameter (as well as hue_order= ) to sns.pointplot() inside the call to g.map() to choose the order of the categorical variable您可以在对sns.pointplot()的调用中将order=参数(以及hue_order= )传递给g.map()以选择分类变量的顺序

att = sns.load_dataset("attention")
g = sns.FacetGrid(att, col="subject", col_wrap=5, height=1.5)
g = g.map(sns.pointplot, "solutions", "score", order=[3,1,2])

在此处输入图像描述

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

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