# CairoMakie ylabel allignment not working

**URL:** <https://discourse.julialang.org/t/cairomakie-ylabel-allignment-not-working/118722>\
**Category:** Visualization\
**Tags:** plotting, makie, cairomakie\
**Created:** [August 28, 2024, 4:19pm UTC](https://discourse.julialang.org/t/cairomakie-ylabel-allignment-not-working/118722 "2024-08-28T16:19:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmdenis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cmdenis/32/211517_2.png) [@cmdenis](https://discourse.julialang.org/u/cmdenis)\
**Post date:** [August 28, 2024, 4:19pm UTC](https://discourse.julialang.org/t/cairomakie-ylabel-allignment-not-working/118722/1 "2024-08-28T16:19:52Z")

</div>

Hello,

I’m new to Makie (used to use Plots before). I’ve been trying to align the ylabels for many subplots using the `CairoMakie` package. I’m able to align them, but for some reason there is some overlap with the tick marks of the plot… Here is my minimal working example:

```julia
f = Figure()

ax1 = Axis(f[1, 1], title = "Axis 1", ylabel = "y label", ytickformat = "{:.3f}")
ax2 = Axis(f[2, 1], title = "Axis 2", ylabel = "y label", xlabel = "x label")
ax3 = Axis(f[2, 2], title = "Axis 3", xlabel = "x label", xtickformat = "{:.3f}", xticklabelrotation = pi/4)

# Here is my addition to the code in the Makie tutorial
lines!(ax1, rand(length(times))*1e5)
lines!(ax2, rand(length(times))*1e2)

yspace = maximum(tight_yticklabel_spacing!, [ax1, ax2])
xspace = maximum(tight_xticklabel_spacing!, [ax2, ax3])

ax1.yticklabelspace = yspace
ax2.yticklabelspace = yspace

ax2.xticklabelspace = xspace
ax3.xticklabelspace = xspace

f

```

This yields this:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/f/ef53f1aa2f33910c142909ce391d457206b41721.jpeg)

The code comes from [this makie tutorial](https://docs.makie.org/v0.21/reference/blocks/axis) which works fine before I add the lines to the plot. As you can see, the label is hidden by the tick labels.

Am I doing something wrong here? Sorry if this is a newbie question 🙂

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [August 28, 2024, 6:24pm UTC](https://discourse.julialang.org/t/cairomakie-ylabel-allignment-not-working/118722/2 "2024-08-28T18:24:29Z")

</div>

Ah that’s tricky 🙂 The reason is that these days, the limits of an Axis don’t immediately update when a plot is added. That’s a performance optimization.

So when you measure the tick spacing, it’s not for the limits you see in the final plot, it’s for the initial limits. That’s why they’re too small.

To adjust the limits early, call `reset_limits!(ax)` on each axis.

---

<div class="post-metadata">

**Author:** ![cmdenis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cmdenis/32/211517_2.png) [@cmdenis](https://discourse.julialang.org/u/cmdenis)\
**Post date:** [September 4, 2024, 5:01pm UTC](https://discourse.julialang.org/t/cairomakie-ylabel-allignment-not-working/118722/3 "2024-09-04T17:01:56Z")

</div>

Amazing! Thank you, that works!

For other people in a similar position, here is the fix in context:

```julia
f = Figure()
	
ax1 = Axis(f[1, 1], title = "Axis 1", ylabel = "y label", ytickformat = "{:.3f}")
ax2 = Axis(f[2, 1], title = "Axis 2", ylabel = "y label", xlabel = "x label")
ax3 = Axis(f[2, 2], title = "Axis 3", xlabel = "x label", xtickformat = "{:.3f}", xticklabelrotation = pi/4)
	
# Here is my addition to the code in the Makie tutorial
times = 0:1000
lines!(ax1, rand(length(times))*1e5)
lines!(ax2, rand(length(times))*1e2)

# Reset limits
reset_limits!(ax1)
reset_limits!(ax2)
reset_limits!(ax3)
	
yspace = maximum(tight_yticklabel_spacing!, [ax1, ax2])
xspace = maximum(tight_xticklabel_spacing!, [ax2, ax3])
	
ax1.yticklabelspace = yspace
ax2.yticklabelspace = yspace
	
ax2.xticklabelspace = xspace
ax3.xticklabelspace = xspace
	
f

```

(also note a typo in the original question: I forgot to define the variable `time`)
