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!
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!
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()
Notice that text
is a string so you can add either x
or y
or both if you'd like.