Seaborn条形图y轴的值与预期值不同

时间:2019-10-20 11:59:27

标签: python pandas matplotlib seaborn

Seaborn条形图中的y值不同于我的数据显示。

我的数据显示:

yearmonth
2018-10     763308.0
2018-11     708366.0
2018-12     703952.0
2019-01     844039.0
2019-02     749583.0
2019-03     826114.0
2019-04     951304.0
2019-05    1042708.0
2019-06    1043556.0
2019-07    1201030.0
2019-08    1065393.0
2019-09     881391.0
Freq: M, Name: csp_workload, dtype: float64

情节代码是:

plt.figure(figsize=(15,5))
sns.barplot(x="yearmonth", y="workload", data = df_all, ci=0)
plt.tight_layout()

输出显示的值小于数据。例如,2018-10的值在条形图中显示约1,800,但应该在763308左右。我可以做些什么来纠正此问题?

1 个答案:

答案 0 :(得分:0)

我尝试了您的代码,它对我有用。 我所做的唯一一件事就是确保可以将Yearmonth正确地读取为日期格式:

pd.to_datetime(df['yearmonth'], format='%Y-%m')

enter image description here

您会注意到yearmonth列更改为

  0    2018-10-01
  1    2018-11-01
  2    2018-12-01
相关问题