Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

How to annotate last item in line graph

Hello I am generating a line graph that has an unknown number of (x,y) elements. How can I annotate the last item without knowing the number of elements?

In this code example (Line Charts). The last index (index 11) is very clearly referenced. Is there some more generic way to do this e.g. y_trace[last element]?

annotations.append(dict(xref=‘paper’, x=0.95, y=y_trace[11],
xanchor=‘left’, yanchor=‘middle’,

Thank you!


The last element of a list or 1D- array has the index -1. Hence, in your case,set:

Thank you, knew it had to be something like that. Will try and let you know!