当我的数据在我的字典中有完整日期时,我不知道如何在使用 matplotilib 绘图时更改日期格式,我只绘制小时、分钟、秒
from datetime import datetime
import matplotlib.pyplot as plt
dico = {'A01': [(u'11/10/12-08:00:01', 2.0), (u'11/10/12-08:10:00', 10.0), \
(u'11/10/12-08:20:01', 5.0), (u'11/10/12-08:30:01', 15.0), \
(u'11/10/12-08:40:00', 7.0), (u'11/10/12-08:50:01', 45.0)],
'A02': [(u'11/10/12-08:00:01', 10.0), (u'11/10/12-08:10:00', 12.0), \
(u'11/10/12-08:20:01', 15.0), (u'11/10/12-08:30:01', 10.0), \
(u'11/10/12-08:40:00', 17.0), (u'11/10/12-08:50:01', 14.0)]}
x = []
y = []
for key in sorted(dico.iterkeys()):
#in Python3
#for key in sorted(dico.keys()):
points = [(datetime.strptime(i[0], "%d/%m/%y-%H:%M:%S"), \
i[1]) for i in dico[key]]
points.sort()
x, y = zip(*points)
plt.plot(x, y, label=key)
# plotting
plt.gcf().autofmt_xdate()
plt.legend(loc='upper right')
plt.xlabel('Dates')
plt.ylabel("titre")
plt.title("Modbus")
plt.show()