【问题标题】:How to format axis in Python如何在 Python 中格式化坐标轴
【发布时间】:2017-06-04 11:32:47
【问题描述】:

我想将 xaxis 格式化为 dd:mm HH:MM。我的代码:

plt.figure(figsize=(20,10))
plt.plot('a', "r.",data=xxx, markersize=1.5)
plt.axis(["2017-04-24 0:00", "2017-04-24 23:59", 0, 400])
plt.grid(True)
plt.show()

我的输出格式是:dd:mm HH。我该如何解决?我不知道;/

【问题讨论】:

    标签: python-3.x datetime matplotlib


    【解决方案1】:

    您需要在轴上添加日期格式化程序:

    from matplotlib.dates import DateFormatter
    
    # your plot set-up code...
    plt.gca().xaxis.set_major_formatter(DateFormatter("%m:%d %H:%M"))
    # etc.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-21
      • 2012-09-04
      • 1970-01-01
      • 1970-01-01
      • 2018-09-08
      • 2018-03-28
      相关资源
      最近更新 更多