2011-04-07 36 views
2

我有時間使用包含毫秒的datetime.datetime.strptime格式化數據。數據可以從幾分鐘到幾個小時。當我使用pyplot進行繪圖並放大時,似乎最小刻度標記是1秒。看來,matplotlib的TickHelper RRuleLocator只有一個SecondLocator。放大時有沒有辦法包含毫秒分辨率?在python matplotlib.dates中繪製毫秒

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() 

回答

1

Matplotlib使用Matlab的數字(1970年以來的秒數)作爲日期。如果你有毫秒,你必須將日期轉換爲「數字」:

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

和情節ntimes而不是times