4

I want to display the x (or y) values within my figure in Matplotlib (like the following figure.). Can anyone guide me with that?

Many thanks!

enter image description here

K.N
  • 871
  • 2
  • 10
  • 30

1 Answers1

2

You can try using annotate. Here is a code example:

import numpy as np
import matplotlib.pyplot as plt

Y = np.random.rand(10, 1)
X = np.arange(10)
plt.plot(X, Y)
for x, y in zip(X, Y):
    plt.annotate(text=str(y[0])[:5], xy=(x, y))
plt.show()

Will output this: enter image description here

Notice that text is a string so you can add either x or y or both if you'd like.

Ofek Glick
  • 999
  • 2
  • 9
  • 20