36

For example in the following code:

import numpy as np
import matplotlib.pyplot as plt

N = 10
x = [1,2,3,4,5,6,7,8,9,10]
y = np.random.rand(N)

plt.scatter(x, y)
plt.show()

I get the following plot

enter image description here

as you can see, in the x axis only the even values appear. How to force matplotlib to show all values, that is 1 2 3 4 5 6 7 8 9 10?

jsguy
  • 1,979
  • 1
  • 22
  • 35
  • 1
    By "all values" do you mean "all values in the input set" or "all integers in the input range"? For instance, if your passed x values `[1, 2.3, 5.2]`, would you want to see 1, 2.3 and 5.2 on the x axis, or 1, 2, 3, 4, 5, and 6? – BrenBarn Feb 13 '15 at 19:08
  • I would want to see, 1 2.3 and 5.2 – jsguy Feb 13 '15 at 19:09

1 Answers1

41

Use plt.xticks(x). See the documentation.

Note that using only the input values for ticks will usually be confusing to a viewer. It makes more sense to use evenly spaced ticks.

BrenBarn
  • 228,001
  • 34
  • 392
  • 371