# Ticks with integer numbers only (instead of fractional values)

**URL:** https://discourse.julialang.org/t/ticks-with-integer-numbers-only-instead-of-fractional-values/87267
**Category:** Visualization
**Tags:** question, plotting
**Created:** [September 14, 2022, 11:16am UTC](https://discourse.julialang.org/t/ticks-with-integer-numbers-only-instead-of-fractional-values/87267 "2022-09-14T11:16:18Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![benoitseron](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@benoitseron](https://discourse.julialang.org/u/benoitseron)
#### Post date: [September 14, 2022, 11:16am UTC](https://discourse.julialang.org/t/ticks-with-integer-numbers-only-instead-of-fractional-values/87267/1 "2022-09-14T11:16:18Z")

</div>

I am looking to make a scatter plot some values with x values that can only be integers (1,2,3…).

By default, Julia will sometimes use x ticks that are integers values, or sometimes as floats, depending on the range of x-values:

```julia
using Plots 

n_data = 14
x = collect(1:n_data)
y = rand(n_data)

scatter(x, y)

```

Taking n\_data = 10, I get x ticks at (2,4,6,…) as I wish to obtain but with n\_data = 14 I obtain fractional values of (2.5,5,7,5,…).

How can I force Julia to only display integers values as x ticks?

Thanks in advance!

---

<div class="post-metadata">

### Author: ![this\_josh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/this_josh/32/42679_2.png) [@this\_josh](https://discourse.julialang.org/u/this_josh)
#### Post date: [September 14, 2022, 11:25am UTC](https://discourse.julialang.org/t/ticks-with-integer-numbers-only-instead-of-fractional-values/87267/2 "2022-09-14T11:25:54Z")

</div>

It would be nice if you could force ints/only use the x values specified, but I don’t know of a way. This works though

```nohighlight
scatter(x, y, xticks = x)

```

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [September 14, 2022, 11:40am UTC](https://discourse.julialang.org/t/ticks-with-integer-numbers-only-instead-of-fractional-values/87267/3 "2022-09-14T11:40:48Z")

</div>

One trick can be this one:

```julia
julia> x = 14*rand(20);

julia> function int_ticks(x; step=1) 
           imin = floor(Int, minimum(x))
           imax = ceil(Int, maximum(x))
           return range(imin, imax, step=step)
       end
int_ticks (generic function with 2 methods)

julia> scatter(x, rand(20), xticks=int_ticks(x; step=2))

```

or, to be sure that the extrema of the ticks appear:

```julia
julia> scatter(x, rand(20), xticks=int_ticks(x; step=2), xlims=extrema(int_ticks(x)))`

```

Then you get:

![image](https://global.discourse-cdn.com/julialang/original/3X/8/1/81e7b849160e2383d02506c96fb0c4eb1428e23e.png)

In other words, you can set anything to be the `xticks`, so you can do that by hand, such as `xticks=0:2:14`.
