Reputation: 67
I am trying to put xticks in a plt figure. However, ticks start from 0 while I want to start from 1 how can I fix this? I tried this (based on a similar question I found) but still nothing.
import numpy as np
import matplotlib.pyplot as plt
y= np.array([[1], [2], [0.5], [1.4],[5], [4], [3.5], [1.2]])
plt.figure(1)
plt.plot(y, marker="o")
x_ticks = np.arange(1, len(y), 5)
plt.xticks(x_ticks)
thanks a lot!
Upvotes: 1
Views: 1307
Reputation: 12496
You can specify a x
array to be used to draw the plot:
x = np.arange(1, len(y) + 1, 1)
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()
Upvotes: 1