Makie: multiple y-axes align yticks

I’m trying to make plots with multiple y-axes in Makie.
I would like that the ticks of all y-axes are aligned with respect to the others y-axis.

using GLMakie
using LaTeXStrings
using Statistics

t = [0; 1; 2; 3; 4; 5]
y1 = [9; 7; 5; 1; 3; 5]
y2 = [12; 25; 23; 16; 34; 19]
y3 = [0; -1; -2; -3; -4; -5]

yticks1 = LinRange(minimum(y1) * 0.9, maximum(y1) * 1.1, 5)
yticks2 = LinRange(minimum(y2) * 0.9, maximum(y2) * 1.1, 5)
yticks3 = LinRange(minimum(y3) * 0.9, maximum(y3) * 1.1, 5)



fig = Figure(size = (1600, 900))

ax1 = Axis(fig[1, 1],
           title  = "Test 1",
           xlabel = L"Time $t$ in $[s]$",
           ylabel = L"Values $V$ in $[unit]$",
           yticklabelcolor = :blue,
           ylabelcolor = :blue,
           xminorgridvisible = true,
           yminorgridvisible = true,
           xminorticks = IntervalsBetween(4),
           yminorticks = IntervalsBetween(4),
           yticks = yticks1
          )

ax2 = Axis(fig[1, 1],
           ylabel = L"Values $V$ in $[unit]$",
           yticklabelcolor = :red,
           yaxisposition = :right,
           ylabelcolor = :red,
           yticks = yticks2
          )

ax3 = Axis(fig[1, 1],
           ylabel = L"Values $V$ in $[unit]$",
           yticklabelcolor = :green,
           yaxisposition = :right,
           ylabelcolor = :green,
           yticklabelpad = 64.0,
           yticks = yticks3
          )

hidespines!(ax2)
hidespines!(ax3)
hidexdecorations!(ax2)
hidexdecorations!(ax3)


lines!(ax1,
       t,
       y1,
       label = L"line $y1$",
       color = :blue
      )

lines!(ax2,
      t,
      y2,
      label = L"line $y2$",
      color = :red
     )

lines!(ax3,
       t,
       y3,
       label = L"line $y3$",
       color = :green
      )

display(fig)

In the example above I tried to set the y-ticks myself on all three y-axes, without success.
As can be seen in the plot below:

It is also odd that despite specifying 5 y-ticks for all y-axes, the first one displays only 4 ticks, the second one three ticks, and only the last one displays the required 5 ticks.

Does someone knows what I’m doing wrong?

Apparently setting the ylimit!() for all axes solve the issue.

Edit: Here’s an example if someone has the same issue:

using Makie
using LaTeXStrings
using Statistics

t = [0; 1; 2; 3; 4; 5]
y1 = [9; 7; 5; 1; 3; 5]
y2 = [12; 25; 23; 16; 34; 19]
y3 = [0; -1; -2; -3; -4; -5]

rng1 = abs(maximum(y1) - minimum(y1)) * 0.05
rng2 = abs(maximum(y2) - minimum(y2)) * 0.05
rng3 = abs(maximum(y3) - minimum(y3)) * 0.05

yticks1 = LinRange(floor(minimum(y1) - rng1), ceil(maximum(y1) + rng1), 5)
yticks2 = LinRange(floor(minimum(y2) - rng2), ceil(maximum(y2) + rng2), 5)
yticks3 = LinRange(floor(minimum(y3) - rng3), ceil(maximum(y3) + rng3), 5)



fig = Figure(size = (1600, 900))

ax1 = Axis(fig[1, 1],
           title  = "Test 1",
           xlabel = L"Time $t$ in $[s]$",
           ylabel = L"Values $V$ in $[unit]$",
           yticklabelcolor = :blue,
           ylabelcolor = :blue,
           xminorgridvisible = true,
           yminorgridvisible = true,
           xminorticks = IntervalsBetween(4),
           yminorticks = IntervalsBetween(4),
           yticks = yticks1
          )

ax2 = Axis(fig[1, 1],
           ylabel = L"Values $V$ in $[unit]$",
           yticklabelcolor = :red,
           yaxisposition = :right,
           ylabelcolor = :red,
           yticks = yticks2
          )

ax3 = Axis(fig[1, 1],
           ylabel = L"Values $V$ in $[unit]$",
           yticklabelcolor = :green,
           yaxisposition = :right,
           ylabelcolor = :green,
           yticklabelpad = 64.0,
           yticks = yticks3
          )

ylims!(ax1, floor(minimum(y1) - rng1), ceil(maximum(y1) + rng1))
ylims!(ax2, floor(minimum(y2) - rng2), ceil(maximum(y2) + rng2))
ylims!(ax3, floor(minimum(y3) - rng3), ceil(maximum(y3) + rng3))
hidespines!(ax2)
hidespines!(ax3)
hidexdecorations!(ax2)
hidexdecorations!(ax3)


lines!(ax1,
       t,
       y1,
       label = L"line $y1$",
       color = :blue
      )

lines!(ax2,
      t,
      y2,
      label = L"line $y2$",
      color = :red
     )

lines!(ax3,
       t,
       y3,
       label = L"line $y3$",
       color = :green
      )

fig
save("test2.png", fig)

I think you’re looking for linkyaxes!(ax1, ax2)?

I tried without success.

I recently ran into the same issue where I have two axes with a different scales, and came to pretty much the same solution of manually having to force the major ticks to be coaligned by specifying the limits and ticks.

Linkaxes is only for exactly the same limits. The solution with manual ticks and manual limits is the right one. I don’t think you can have it simpler because if you don’t specify limits, it’s unlikely any ticks will be in the same locations by chance.