0

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

3
  • Use plt.annotate on the last value of x/y Commented Mar 1, 2022 at 10:27
  • @mozway I don't know how to do it dynamically. Can you show an example please ? Commented Mar 1, 2022 at 10:30
  • 1
    Sure, see here Commented Mar 1, 2022 at 10:35

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Can you provide an image?
0

You could use the Plotly Library for this.

e.g.

import plotly.express as px
df = px.data.gapminder().query("continent == 'Oceania'")
fig = px.line(df, x='year', y='lifeExp', color='country', markers=True)
fig.show()

This will give you an output: plotly marker example

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.