1

the code below plots the data with the marker as a green spot. BUT I want the marker to be the actual value of y. So instead of the green dots the marker would be 10, 22.5, 43.34. Anyone done this please?

import numpy as np
import matplotlib.pyplot as plt


x = [ 10,20,30] 
y = [ 10,22.5 ,43.34 ]

x_new = 100
y_new = np.interp(x_new, x, y)

print(y_new)

plt.plot(x, y, "og-");

plt.show()

1 Answer 1

4

I think you are looking for annotate instead:

plt.plot(x, y, "og-",markersize=40);

for xx,yy in zip(x,y):
    plt.annotate(f'{yy}', (xx, yy), va='center',ha='center', color='w')

Output:

enter image description here

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

1 Comment

thank you so much AGAIN!!! I didn't even know annotate existed. I REALLY have to read the docs more. Thanks again. I have to mod the answer as I am using plt.subplots(nrows=2, ncols=1) and .plot(ax=axes[0] ) thanks again for such wonderful help

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.