【问题标题】:How to sort my bar values in a specific order?如何按特定顺序对我的条形值进行排序?
【发布时间】:2021-06-24 10:20:33
【问题描述】:
sns.catplot(x='Injury Severity', kind = 'count', data=df)
plt.title('Number of incidents by Injury Severity', size=20)
plt.ylabel('Total incidents in Montgomery County, Maryland', size = 14)
plt.xlabel('')
plt.xticks(rotation=90)

this I want to use fancy indexing to reorder my plot

【问题讨论】:

  • 然后您只需按顺序将它们呈现给plt。你被困在哪里了?
  • 请通过intro tour、help center 和how to ask a good question 了解本网站的工作原理并帮助您改进当前和未来的问题,从而帮助您获得更好的答案。不接受站外链接和文字图片;您的帖子必须是独立的,符合本网站的目的。
  • 我被困在试图重新排列情节中的条形。按这个顺序将它们呈现给 plt 是什么意思?
  • 他们不是按照你在参数列表中给他们的顺序绘制的吗?我不能对你的代码做任何具体的引用,因为你还没有完成你的MRE - Minimal, Reproducible Example。
  • 我的情节在我的 spyder IDE 上是完美的,但是,在 google colab 上,情节有不同的顺序。

标签: python seaborn data-science


【解决方案1】:

我认为您想要的只是简单地使用sns.catplot 的order 参数

import seaborn as sns

tips = sns.load_dataset("tips")

order = ['Sun', 'Fri', 'Thur', 'Sat']
ax = sns.catplot(x="day", data=tips, order=order, kind='count')

【讨论】:

    猜你喜欢
    • 2020-11-05
    • 1970-01-01
    • 1970-01-01
    • 2016-11-01
    • 1970-01-01
    • 2020-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多