Seaborn 条形图 y 轴的值与预期不同 [英] Seaborn bar plot y axis has different values than expected

查看:56
本文介绍了Seaborn 条形图 y 轴的值与预期不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Seaborn 条形图中的 y 值与我的数据显示的不同.

The y values in the Seaborn barplot are different than what my data shows.

我的数据显示:

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 左右.我可以做些什么来纠正这个问题?

The output shows values less than the data. For example, the values for 2018-10 display about 1,800 in the bar plot, but it should be around 763308. Is there something I can do to correct this?

推荐答案

我尝试了您的代码,并且对我有用.我所做的唯一一件事就是确保 yearmonth 被正确读取为日期格式:

I tried your code and it worked for me. The only thing I've made was to make sure that yearmonth is being read properly as date format:

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

您会注意到 yearmonth 列更改为

You will notice that the yearmonth column changes to

  0    2018-10-01
  1    2018-11-01
  2    2018-12-01

这篇关于Seaborn 条形图 y 轴的值与预期不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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