From a data file in hdf5 format I am plotting three lines using
if (nbnd<3):
color=f'C{nbnd}'
ax.plot(x, y, c=color, lw=2.0, alpha=0.8, label = lbl[nbnd] if nbnd < 3 and i == 0 else None)
I want to grep maximum value of nbnd=2 along Y-axis and write that value on top of the line (corresponding to nbnd=2) with an arrow. A sample is shown in the plot where 0.032 with arrow is manually done while I need this kind of notation in matplotlib automatically.
A similar accepted answer is given here: https://stackoverflow.com/questions/43374920/how-to-automatically-annotate-maximum-value-in-pyplot [https://i.sstatic.net/TPwp7.png]
But I could not get it done for my work.
I used
ymax = max(y)
xpos = y.index(ymax)
xmax = x[xpos]
ax4.annotate('local max', xy=(xmax, ymax), xytext=(xmax, ymax+5),
arrowprops=dict(facecolor='black', shrink=0.05),
)
It gives me below error:
ax4.annotate('local max', xy=(xmax, ymax), xytext=(xmax, ymax+5),
NameError: name 'xmax' is not defined

listornp.ndarray?NameError: name 'xmax' is not definedindicates that you didn't run above code as written. Clearlyxmaxgets a value in the third line.