分组条形图——如何让sns尊重行的顺序? [英] Grouped bar chart -- how to make sns respect order of rows?

查看:63
本文介绍了分组条形图——如何让sns尊重行的顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多级数据框,按 level=1 上的值排序

I have a multilevel data frame, sorted by values on level=1

我想制作一个分组条形图.当我这样做

I want to make a grouped bar plot. When I do

ax = sns.barplot(ax=ax, x="level0", y="values",
             hue="level1", data=data)

Sns 决定按 level1 对索引进行排序.

Sns decides to sort index by level1.

有没有办法让sns在制作分组条形图时尊重行的顺序?

Is there a way to make sns respect the order of rows when making grouped bar plots?

推荐答案

根据@ImportanceOfBeingErnest 的评论,您可以使用 orderhue_order 参数来控制条形沿 x 轴出现的顺序.

As per the comment from @ImportanceOfBeingErnest, you can use the order and hue_order parameters to control in which order the bars appear along the x-axis.

这篇关于分组条形图——如何让sns尊重行的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆