在 python matplotlib.dates 中绘制毫秒图
我有使用 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()
I have time tagged data formatted using datetime.datetime.strptime that includes milliseconds. The data can span from a few minutes to a few hours. When I plot using pyplot and zoom in, it seems the minimum tick mark is 1 second. It appears that matplotlib's TickHelper RRuleLocator only has a SecondLocator. Is there a way to include millisecond resolution when zoomed in?
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Matplotlib 使用类似 Matlab 的数字(自 1970 年以来的秒数)来表示日期。如果有毫秒,则必须将日期转换为“数字”:
并绘制
ntimes
而不是times
。Matplotlib uses Matlab like numbers (seconds since 1970) for dates. If you have milliseconds, you must convert the dates to 'number':
and plot
ntimes
instead oftimes
.