# How to align x axis in GR

**URL:** <https://discourse.julialang.org/t/how-to-align-x-axis-in-gr/68626>\
**Category:** Visualization\
**Tags:** question, plots, gr\
**Created:** [September 23, 2021, 12:02pm UTC](https://discourse.julialang.org/t/how-to-align-x-axis-in-gr/68626 "2021-09-23T12:02:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ohmsweetohm1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ohmsweetohm1/32/49126_2.png) [@ohmsweetohm1](https://discourse.julialang.org/u/ohmsweetohm1)\
**Post date:** [September 23, 2021, 12:02pm UTC](https://discourse.julialang.org/t/how-to-align-x-axis-in-gr/68626/1 "2021-09-23T12:02:09Z")

</div>

How to align the axis?

```julia
p1 = Plots.plot(rand(10), label="A very loooooooooooooooong label")
p2 = Plots.plot(rand(10), label="A short label")
Plots.plot(p1, p2, layout=(2,1), legend=:outerright)

```

 ![bug](https://global.discourse-cdn.com/julialang/original/3X/2/3/23a262c35c0bcb9bb6770550361be5fb1bf8afd9.png)

---

<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:** [September 23, 2021, 12:43pm UTC](https://discourse.julialang.org/t/how-to-align-x-axis-in-gr/68626/2 "2021-09-23T12:43:44Z")

</div>

You can check if the workaround [in this post](https://discourse.julialang.org/t/plots-jl-linked-aligned-x-axis-figures-with-outer-legends/63523/7) is useful.

In this case it could be implemented as follows:

```julia
using Printf, Plots; gr()

y1 = rand(10); y2 = rand(10);
n = length(y1)
x = 1:n
xstr = [@sprintf("%.1f", xi) for xi in x]
label1 = "A very loooooooooooooooong label"
label2 = "A short label"
xpad = 11 # adjust function of font size

a = plot(y1, label=label1, widen=false, xticks=(x, xstr))
plot!(x, zero(x) .+ ylims(a)[1], lc=:black, label=false)
plot!(zero(x) .+ xlims(a)[1], y1, lc=:black, label=false)
vspan!([x[n], x[n]+xpad], c=:white, lc=:white, label=false)

b = plot(y2, label=label2, widen=false, xticks=(x, xstr))
plot!(x, zero(x) .+ ylims(b)[1], lc=:black, label=false)
plot!(zero(x) .+ xlims(b)[1], y2, lc=:black, label=false)
vspan!([x[n], x[n]+xpad], c=:white, lc=:white, label=false)

plot(a,b, link=:x,layout=(2,1),xlims=(x[1],x[n] + xpad),legend=:topright,showaxis=false)

```

 ![Plots_gr_linked_subplots_long_legends](https://global.discourse-cdn.com/julialang/original/3X/5/2/524f800aa9539ea17299173b2ada7adb172e7b8b.png)

---

<div class="post-metadata">

**Author:** ![ohmsweetohm1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ohmsweetohm1/32/49126_2.png) [@ohmsweetohm1](https://discourse.julialang.org/u/ohmsweetohm1)\
**Post date:** [September 25, 2021, 6:11pm UTC](https://discourse.julialang.org/t/how-to-align-x-axis-in-gr/68626/3 "2021-09-25T18:11:55Z")

</div>

Very verbose but ok. Thx anyway.
