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?