is it possible to create plot labels based on conditions? As one can see below, I am creating plots within a loop. The issue is that not all locations of the dataset contain data to plot as time series. Hence I want to label only those timesteps which contain data. I have 8 locations of which only 4 contain data. Currently, a legend for all locations is plotted:
I would like to do something like:
lineplot = plt.plot(timesteps, skin_celsius, label='%s. storm location' % i with condition if time series contains no NaN data)
is something like this possible?
This is the whole code for the plot
fig2 = plt.figure(figsize=(20, 20), dpi=300)
# change this loop to extract time series data for day -10 + 10days around stormtrack data.
for i, dummy in enumerate(lati):
dsloc = SSTskin_subfile_masked.sel(lon=loni[i], lat=lati[i], method='nearest')
dstime = SSTskin_subfile_masked.sel(time=timei[i], lon=loni[i], lat=lati[i], method='nearest') #find point data within timeseries data
skin_celsius = (dsloc['analysed_sst']) - 273.15
timesteps = dsloc.time.values
timestep = dstime.time.values
timevalue = ((dstime['analysed_sst']).values) - 273.15
#Here I want to add a condition to the labelling.
lineplot = plt.plot(timesteps, skin_celsius, label='%s. storm location' % I)
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)
plt.legend()