【问题标题】:Matplotlib: Display epoch timestamp as regular date in a plotMatplotlib:将纪元时间戳显示为绘图中的常规日期
【发布时间】:2018-08-24 17:53:13
【问题描述】:

这是我绘制 col_A 与时间的代码:

ax[0].plot(data_df['time'], data_df['col_A'] , color = 'black')

剧情是这样的:

x 轴 time 当前处于“纪元时间戳”单位 (https://www.freeformatter.com/epoch-timestamp-to-date-converter.html)。我可以在图中使用常规日期显示 x 轴吗?谢谢!

【问题讨论】:

  • 为什么不在绘图前转换时间戳或以所需格式创建新列?例如,请参阅this。谷歌上有很多例子。
  • 如果在plot 函数中添加data_df['time'].astype('datetime64[s]') 而不是只添加data_df['time'] 是否有效?

标签: python matplotlib timestamp


【解决方案1】:

您可以尝试在绘图函数中添加data_df['time'].astype('datetime64[s]') 而不是仅添加data_df['time']

ax[0].plot(data_df['time'].astype('datetime64[s]'), data_df['col_A'] , color = 'black')

【讨论】:

    猜你喜欢
    • 2018-08-03
    • 2019-03-04
    • 1970-01-01
    • 2013-01-08
    • 1970-01-01
    • 2015-10-20
    • 2021-03-01
    • 2022-08-04
    • 2020-02-21
    相关资源
    最近更新 更多