我正在编写一个python应用程序,它从无线传感器网络收集温度和时间。在
简而言之,我的代码片段如下:a.set_facecolor((0.9, 0.9, 1.0))
myFmt = mdates.DateFormatter('%H:%M')
a.xaxis.set_major_formatter(myFmt)
a.xaxis_date()
a.set_title('WSN temperature')
a.set_ylabel('Temp ' + u"\u2103")
a.set_xlabel('Time')
a.grid(True)
a.set_ylim([-20, 40]) #values found in the collectsensor.py
a.yaxis.set_ticks(np.arange(-20, 40, 5))
a.set_xlim([timeIntervalLeft, timeIntervalRight])
cmap = clr.LinearSegmentedColormap.from_list("", ["darkblue", "blue", "violet", "yellow", "orange", "red"])
cmap2 = clr.LinearSegmentedColormap.from_list("", ["red", "orange", "yellow", "violet", "blue", "darkblue"])
a.scatter(timeList, tempList, c=tempList, s=100, cmap=cmap)
y = tempList
s = pd.Series(y, index=timeList)
# convert dates to numbers first
inxval = mdates.date2num(s.index.to_pydatetime())
points = np.array([inxval, s.values]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
lc = LineCollection(segments, cmap=cmap2, linewidth=3)
lc.set_array(inxval)
a.add_collection(lc)
有了这个代码,我得到了类似于:
你可以看到,散射可以利用cmap,因此随着y值的增加,点变得“更热”。我找了一些类似的绘图功能,但我没有找到任何可以为我工作。在
但这里的颜色与y轴上的温度没有真正的关系,而是沿着所有cmap颜色分布。在