1

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!

Zephyr
  • 11,891
  • 53
  • 45
  • 80
teratoulis
  • 57
  • 5

1 Answers1

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()

enter image description here

Zephyr
  • 11,891
  • 53
  • 45
  • 80