Skip to content
Advertisement

How to automatically annotate maximum value in pyplot

I’m trying to figure out how I can automatically annotate the maximum value in a figure window. I know you can do this by manually entering in x,y coordinates to annotate whatever point you want using the .annotate() method, but I want the annotation to be automatic, or to find the maximum point by itself.

Here’s my code so far:

JavaScript

Here's the figure that it generates

Advertisement

Answer

I don’t have data of macrodata.csv to go with. However, generically, assuming you have x and y axis data as an list, you can use following method to get auto positioning of max.

Working Code:

JavaScript

Plot :
enter image description here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement