The script below creates a figure with time-series data (temperature) for 4 different locations:
The red dots on the lines indicate a storm event at that location.
Now, I want to add a legend for the different time-series graphs (lines) representing the location at which the time-series data was taken (longitude and latitude). The temperature data is one variable of a NetCDF file (time times lat times lon coordinates). I have managed that the 2nd legend does not overlay the first legend, BUT I am still missing that the legend for the lines represents ALL lines, not one only.
Can anyone help? Thanks!
lati = stormtrack_lat.values
loni = stormtrack_lon.values
timei = stormtrack_datetime.values
fig2 = plt.figure(figsize=(20, 20), dpi=300)
for i, dummy in enumerate(lati):
dsloc = SSTskin_file.sel(lon=loni[i], lat=lati[i], method='nearest')
dstime = SSTskin_file.sel(time=timei[i], lon=loni[i], lat=lati[i], method='nearest')
skin_celsius = (dsloc['analysed_sst']) - 273.15
timesteps = dsloc.time.values
timestep = dstime.time.values
timevalue = ((dstime['analysed_sst']).values) - 273.15
lineplot = plt.plot(timesteps, skin_celsius)
dotplot = plt.plot(timestep, timevalue, "or")
plt.title('Skin SST over time at storm track locations', fontsize = 20 )
plt.xlabel('Date', fontsize = 16)
plt.ylabel('Skin SST in $^{\circ}C$', fontsize = 16)
plt.xticks(fontsize = 16)
plt.yticks(fontsize = 16)
legend1 = plt.legend(lineplot, ['Temperature 1', 'Temperature 2', 'Temperature 3', 'Temperature 4'], loc = 1, fontsize = 16);
#Here I am missing that ALL lines are represented, not only one.
plt.legend(dotplot, ['Storm track footprint at location and time'], loc = 4, fontsize = 16);
plt.gca().add_artist(legend1)
fig2.savefig('SSTskin_storm_timeseries_test.png', bbox_inches='tight')