首页 > 解决方案 > Seaborn 条形图的简单问题

问题描述

这里的问题相对简单,但我有一个简单的数据框,如下所示:

df.head()

     trigger       count
0   task_appeared   8677
1   status          7410
2   task_created    4046
3   custom_field    2550
4   on_due_date      2116

我想打印出递减的 seaborn 视觉效果,以按降序显示触发器类型列表。我的代码如下:

sns.countplot(x = "trigger", data = df,palette = 'plasma')
             

plt.title("Trigger Popularity")
plt.ylabel("Count of Triggers")
plt.xlabel("Trigger Type")
plt.xticks(rotation=90)

但是我只是得到以下视觉效果。它没有按我原始数据框中列出的降序显示每个触发器的正确​​值计数。我不知道为什么 y 轴应该显示 DF 的计数列指定的值时只显示 0 到 1 的值

Trigger Pop But 的图像应该从 8677 下降

标签: pythonseaborn

解决方案


您已经计算了每种触发器类型的数量

所以你可以使用barplot

sns.barplot(x="trigger", y="count", data=df)
plt.xticks(rotation=90)
plt.title("Trigger Popularity")

输出:

在此处输入图像描述


推荐阅读