【问题标题】:graphing milliseconds in python matplotlib.dates在 python matplotlib.dates 中绘制毫秒数
【发布时间】:2011-04-07 20:16:02
【问题描述】:

我有使用 datetime.datetime.strptime 格式化的时间标记数据,包括毫秒。数据可以跨越几分钟到几个小时。当我使用 pyplot 绘图并放大时,最小刻度线似乎是 1 秒。 matplotlib 的 TickHelper RRuleLocator 似乎只有一个 SecondLocator。有没有办法在放大时包含毫秒分辨率?

receivedTime = datetime.datetime.strptime(str(data[1]), "%H:%M:%S.%f")

fig=plt.figure()
ax=fig.add_axes([0.1,0.1,.8,.8])
fig.autofmt_xdate()

ax.plot(times, prices, color='blue', lw=1, drawstyle='steps-post', label = prices)
plt.show()

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    Matplotlib 使用类似 Matlab 的数字(自 1970 年以来的秒数)作为日期。如果您有毫秒,则必须将日期转换为“数字”:

    import matplotlib.dates as mdates
    ntimes = mdates.num2epoch(times / 1000.0)
    

    并绘制ntimes 而不是times

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-13
      • 2017-02-15
      • 1970-01-01
      • 1970-01-01
      • 2010-12-22
      • 2011-10-28
      相关资源
      最近更新 更多