fix xticks starting from 1 in python with matplotlib
Solution 1:
You can specify a x
array to be used to draw the plot:
x = np.arange(1, len(y) + 1, 1)
Complete Code
import numpy as np
import matplotlib.pyplot as plt
y= np.array([[1], [2], [0.5], [1.4],[5], [4], [3.5], [1.2]])
x = np.arange(1, len(y) + 1, 1)
plt.figure(1)
plt.plot(x, y, marker="o")
plt.show()