python - matplotlib - How to specify the scale for x axis
Question: > **Possible Duplicate:**  
>  [Python, Matplotlib, subplot: How to set the axis
> range?](http://stackoverflow.com/questions/2849286/python-matplotlib-
> subplot-how-to-set-the-axis-range)

I would like to specify the scale of the x-axis for my scatter plot similar to
excel.

For example, I feed in the x axis values as follows:

    
    
    x_values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
    

However, only the numbers with an even 1st digit appear.

Is there a way to make it such that all numbers appear on the x-axis?

Thanks,

Parth


Answer: You need
[`matplotlib.pyplot.xticks`](http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xticks).
In your example:

    
    
    xticks(x_values)
    

Prepend the function call with the module name, depending on your imports.

For instance, in `ipython --pylab` I enter:

    
    
    In [1]: x_values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
    
    In [2]: scatter(x_values, x_values)
    Out[2]: <matplotlib.collections.PathCollection at 0x39686d0>
    
    In [3]: xticks(x_values)
    

and get

![enter image description here](http://i.stack.imgur.com/eiAdn.png)

Note that this leaves some space at the right, because initially the ticks
were up to 120 at every 20. To have it at every 10 without knowing the
maximum, you can make two calls to `xticks`:

    
    
    xticks(range(0, int(xticks()[0][-1])+1, 10))
    

