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

2024-04-25 17:34:29 发布

您现在位置:Python中文网/ 问答频道 /正文

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的值在条形图中显示约1800,但应在763308左右。我能做些什么来纠正这个问题吗?你知道吗


Tags: 数据代码name绘图pltseaborncspfigure
1条回答
网友
1楼 · 发布于 2024-04-25 17:34:29

我试过你的代码,它对我有用。 我所做的唯一一件事就是确保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

相关问题 更多 >