【问题标题】:Is there a way to make Pandas area chart with time axes on x not to overlap?有没有办法让 x 上的时间轴不重叠的 Pandas 面积图?
【发布时间】:2021-12-09 06:43:29
【问题描述】:

我正在尝试显示具有 2 列的时间序列的数据框。这是数据框的示例。

index Alive T-3 Alive T-3 & T+3
12/31/2018 100 80
12/31/2019 120 90
12/31/2020 130 95
12/31/2021 140 98
12/31/2022 150 100
12/31/2023 160 123

这是我用来绘制图表的东西

survived.plot.area(stacked=False)

我遇到的问题是我的时间序列中有 621 个条目,情节最终看起来像这样。有没有办法让它更稀疏?我真的不需要轴上的整个时间序列。甚至几年就足够了。

【问题讨论】:

  • 将索引转换为datetime而不是字符串
  • 成功了!谢谢

标签: python pandas matplotlib charts


【解决方案1】:

正如@It_is_Chris 提到的,索引应该是datetime

survived.index = pd.to_datetime(survived.index) 完成了这项工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 2022-01-15
    • 2020-11-17
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 2020-10-18
    相关资源
    最近更新 更多