2

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

b.j
  • 575
  • 5
  • 18

1 Answers1

1

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
  • 831
  • 2
  • 7
  • 18