我正在使用字典用 python 和 matplotlib 绘制线条我无法弄清楚为什么我的线条的颜色没有改变
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 = []
lstPlot = []
plt.gca().set_color_cycle(["b", "g", "r", "c", "m", "y", "k"])
for key, values in dico.iteritems():
for i in sorted(values):
# date sting to date obj
dateObj = datetime.strptime(i[0], "%d/%m/%y-%H:%M:%S")
line = dateObj, i[1]
lstPlot.append(line)
for i in sorted(lstPlot):
x.append(i[0])
y.append(i[1])
plt.plot(x, y, label=key)
# plotting
plt.legend(loc='upper right')
plt.xlabel('Dates')
plt.ylabel("titre")
plt.title("Modbus")
plt.show()
请注意,我在图例中有不同的颜色,但在情节中没有。