I am coding a python app which collects temperature and time from a wireless sensor network.
Briefly a snippet of my code is like this:
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)
With that code I obtain something like:
You can see that scatter can make use of cmap, so the dots become "hotter" as the y values increase. I looked for something similar for the plot function but I have not found anything that could work for me.
Thanks to ImportanceOfBeingErnest I noticed that previous question How to plot multi-color line if x-axis is date time index of pandas
But here the color is not really related to the temperature in y axes, but it is distributed along all the cmap color.