【问题标题】:Seaborn bar plot y axis has different values than expectedSeaborn 条形图 y 轴的值与预期不同
【发布时间】:2020-02-16 17:53:16
【问题描述】:

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

【问题讨论】:

    标签: python pandas matplotlib seaborn


    【解决方案1】:

    我试过你的代码,它对我有用。 我所做的唯一一件事就是确保正确地将 yearmonth 读取为日期格式:

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

    您会注意到 yearmonth 列更改为

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

    【讨论】:

      猜你喜欢
      • 2019-07-23
      • 1970-01-01
      • 2019-02-18
      • 2019-01-23
      • 2015-01-17
      • 2021-05-02
      • 1970-01-01
      • 2015-06-25
      • 2020-11-20
      相关资源
      最近更新 更多