How to annotate the highest point of each line in the drawing?

How to annotate the highest point of each line in the drawing? I attached the code and the image to clarify my question:

img

First: I want to add an annotate for instance point, star, or any sign to distinguish the highest point of each line in the graph.

Second: I want to assign the name of the line dataset to appear on the graph as a name of the line which drew on the graph.

for i, j in zip(range(1,7, 1), range(1,7, 1)):

            j= np.genfromtxt(f"C:/Users/fadil/Desktop/Project/Segmentation/Exp2_29112021/CT&DCT/DCT/Similartiy Data result/file{i}.txt")
            plt.plot(j, markeredgecolor='none')
            plt.title('SSIM result DynaCT with result CT slices')
            plt.xlabel('DynaCT slices')
            plt.ylabel('structural similarity index measure (SSIM)')
            plt.legend(f"{i}", loc='best',fontsize='xx-small')
            print(i)
plt.show()
cv2.waitKey(0)
cv2.destroyAllWindows()

Solution 1:

To put something in the legend, the label= keyword is used while plotting the element. The legend is called only once, after creating all the curves.

np.argmax() finds the index of the maximum.

import matplotlib.pyplot as plt
import numpy  as np

for i in range(1, 7):
    j = np.random.normal(0.1, 1, 50).cumsum() + np.random.uniform(1, 30)
    j_max = np.argmax(j)
    plt.plot(j, label=f"{i}")
    plt.scatter(j_max, j[j_max], s=100, marker='o', facecolor='none', edgecolor='red', )

plt.title('SSIM result DynaCT with result CT slices')
plt.xlabel('DynaCT slices')
plt.ylabel('structural similarity index measure (SSIM)')
plt.legend(loc='best', fontsize='xx-small')
plt.margins(x=0.01)
plt.tight_layout()
plt.show()

adding a legend and showing the maxima