# Plots.jl : Obtain a graph with alligned ticks on x and y axes

**URL:** <https://discourse.julialang.org/t/plots-jl-obtain-a-graph-with-alligned-ticks-on-x-and-y-axes/74388>\
**Category:** Visualization\
**Tags:** plots\
**Created:** [January 11, 2022, 12:13pm UTC](https://discourse.julialang.org/t/plots-jl-obtain-a-graph-with-alligned-ticks-on-x-and-y-axes/74388 "2022-01-11T12:13:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)\
**Post date:** [January 11, 2022, 12:13pm UTC](https://discourse.julialang.org/t/plots-jl-obtain-a-graph-with-alligned-ticks-on-x-and-y-axes/74388/1 "2022-01-11T12:13:23Z")

</div>

Hey,

Is there a way to force a plot to have the same ticks values on the x and the y axes ? So that the ‘grid’ is symmetric. It will make the reading of my qqplots easier.

---

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [January 11, 2022, 1:05pm UTC](https://discourse.julialang.org/t/plots-jl-obtain-a-graph-with-alligned-ticks-on-x-and-y-axes/74388/2 "2022-01-11T13:05:11Z")

</div>

Can you show some example? `ratio=1.0` keyword makes unit length in x and y be the same but I am not sure about tick values shown in the plot.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 11, 2022, 1:09pm UTC](https://discourse.julialang.org/t/plots-jl-obtain-a-graph-with-alligned-ticks-on-x-and-y-axes/74388/3 "2022-01-11T13:09:11Z")

</div>

I suspect that providing common `lims` should suffice:

```julia
using Plots; gr()
plot(sin, lims=(-3, 3))

```

---

<div class="post-metadata">

**Author:** ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)\
**Post date:** [January 11, 2022, 1:15pm UTC](https://discourse.julialang.org/t/plots-jl-obtain-a-graph-with-alligned-ticks-on-x-and-y-axes/74388/4 "2022-01-11T13:15:05Z")

</div>

Consider the following :

```julia
using Plots
X = randn(1000)
Y = randn(1000)
Y = X .* (1 + Y / 5)
scatter(X,Y)

```

which on my machine produce the following graph :

![simple graph](https://global.discourse-cdn.com/julialang/original/3X/2/7/279fceb83db441ec52939e824db5c0eb01beb702.png)

The ticks are not aligned : the values shown are not the same on the xaxis (-3,-2,-1,0,1,2,3) and the y axis (-4,-2,0,2), resulting in a gray grid behind the points that is not symmetric.

If i do:

```julia
scatter(X,Y,xlims=[-4,4],ylims=[-4,4])

```

this works and gives :

![simple graph](https://global.discourse-cdn.com/julialang/original/3X/1/8/18c841cd7cb1f1e7c077ce774bbe0e0acd6b86b1.png)

However i think this is by chance and i am not sure it will make them symetric in other situation (different size of the plot, etc…), and i do not want to specify by hand the maximum and minimum values !

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [January 11, 2022, 1:31pm UTC](https://discourse.julialang.org/t/plots-jl-obtain-a-graph-with-alligned-ticks-on-x-and-y-axes/74388/5 "2022-01-11T13:31:31Z")

</div>

I am not aware of a built-in function to do that, but you could just supply the `xticks` and `yticks`, making them the same. It isn’t too hard to do “by hand” since you have the `X` and `Y` data right there. For example, `range(start=round(minimum(X),RoundDown),step=2,stop=round(maximum(X),RoundUp))` would give the ticks in your example plot.

---

<div class="post-metadata">

**Author:** ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)\
**Post date:** [January 11, 2022, 1:41pm UTC](https://discourse.julialang.org/t/plots-jl-obtain-a-graph-with-alligned-ticks-on-x-and-y-axes/74388/6 "2022-01-11T13:41:02Z")

</div>

> [@tbeason](#):
>
> I am not aware of a built-in function to do that, but you could just supply the `xticks` and `yticks` , making them the same. It isn’t too hard to do “by hand” since you have the `X` and `Y` data right there. For example, `range(start=round(minimum(X),RoundDown),step=2,stop=round(maximum(X),RoundUp))` would give the ticks in your example plot.

If the minimum value is like 0.9 and the maximum value is like 1.1, plotting from 0 to 2 would be a shame.

Is there a way I could look at how `Plots.jl` computes these values ?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 11, 2022, 1:41pm UTC](https://discourse.julialang.org/t/plots-jl-obtain-a-graph-with-alligned-ticks-on-x-and-y-axes/74388/7 "2022-01-11T13:41:09Z")

</div>

> [@lrnv](#):
>
> and i do not want to specify by hand the maximum and minimum values

Nothing is by hand in Julia…

```julia
xr, yr = extrema.((X,Y))
lims = extrema((xr..., yr...))
scatter(X,Y, lims=lims)

```

---

<div class="post-metadata">

**Author:** ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)\
**Post date:** [January 11, 2022, 1:42pm UTC](https://discourse.julialang.org/t/plots-jl-obtain-a-graph-with-alligned-ticks-on-x-and-y-axes/74388/8 "2022-01-11T13:42:52Z")

</div>

> [@rafael.guerra](#):
>
> Nothing is by hand in Julia…
> 
> ```julia
> xr, yr = extrema(X), extrema(Y)
> lims = min(xr[1], yr[1]), max(xr[2], yr[2])
> scatter(X,Y, lims=lims)
> 
> ```

Plots.jl does not really take the extremum, it gives a little more room to the points. I am sure there is somewhere coded the computation of these limits, i just have to find it 🙂

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 11, 2022, 1:43pm UTC](https://discourse.julialang.org/t/plots-jl-obtain-a-graph-with-alligned-ticks-on-x-and-y-axes/74388/9 "2022-01-11T13:43:52Z")

</div>

> [@lrnv](#):
>
> Plots.jl does not really take the extremum

`scatter(X,Y, lims=lims, widen=true)`

---

<div class="post-metadata">

**Author:** ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)\
**Post date:** [January 11, 2022, 1:45pm UTC](https://discourse.julialang.org/t/plots-jl-obtain-a-graph-with-alligned-ticks-on-x-and-y-axes/74388/10 "2022-01-11T13:45:20Z")

</div>

`widen=true` seemsto be the solution. Thanks a lot this works as expected now 🙂
