In short, I have (a couple of days worth of) glucose values plotted against their timestamps. I have written a function which then layers the glucose values on the same x-axis so I can look for glucose trends. Ultimately, that means that glucose data from a couple of days is plotted with different lines, resulting in the graph below:
Currently, the label says 'Glucose reading' for every color. I am looking to set the label in a way so when the data is being plotted it shows the dates (2019-11-21, 2019-11-22) and so on. I'm really not sure how to do it since I've never dealt with matplotlib legends below and I couldn't really find any useful solutions.
Any guidance would be much appreciated!
EDIT 1:
I am using pandas dataframe. Minimal code example - My legend is positioned in a plotting function like so:
def plotting_function(x, y, isoverlay = False):
years_fmt = mdates.DateFormatter(' %H:%M:%S')
ax = plt.axes()
ax.xaxis.set_major_formatter(years_fmt)
dates = [date.to_pydatetime() for date in x]
if isoverlay:
plt.plot(x, y, label= "Glucose reading" )
else:
plt.plot(x, y, 'rs:', label="Glucose reading")
plt.xlabel("Time of readings")
plt.ylabel("Glucose readings in mmol/L")
plt.legend(ncol=2)
plt.title("Glucose readings plotted against their timestamps")