Home > other >  Python - MatplotLib - Annotate Last Point
Python - MatplotLib - Annotate Last Point

Time:03-01

Wondering How to add Marker Corresponding value to the last point of a series.

To plot my series I use :

var= pd.read_excel("ExcelFilePath")
x = list(var['Date'])
y = list(var['Values'])
plt.plot(x,y,label='blabla')

Which Give (For example) :

enter image description here

How would I get this :

enter image description here

CodePudding user response:

You could use annotate:

import numpy as np

x = np.linspace(0,6.5)
y = np.sin(x)

plt.plot(x,y,label='blabla')

plt.plot(x[-1], y[-1], marker=' ')
plt.annotate(f'({x[-1]:.2f}, {y[-1]:.2f})', (x[-1], y[-1]), ha='right')

output:

enter image description here

CodePudding user response:

You could use the plotly marker example

  • Related