Plot with three y-axes (, so one y-axis has to be double)

Hello,

I need to put on the same graph three lines with different y-axis). I know how to do it with two y-axises (one is right and the other is left).
How to do it with 3 lines, so the left y-axis has to be double.

thank you in advance.
Best

I think the best advice I can give is “don’t”, two axes is already slightly less than one too many.

That said, have you considered

plot(...)
twinx(...)
twinx(...; ymirror=true)

?

2 Likes

thank you,
But here, 2dn and 3rd y-axises overlapped, unfortunately, it’s not doubled

This is an example

Okay, there is probably no simpler alternative than using insets with manual bboxes for that. And the reason is most people would consider that poor visualization. Compared to

plot(
plot(...),
plot(...),
plot(...);
layout=(3,1)
)

the triple-axis plot is just harder to read.

But if you’re using it internally where you can learn to read it once and will then use the same layout many times I guess there is no issue with it if you get it to work.

Have you tried using PyPlot.jl to implement Multiple Yaxis With Spines ?

In Makie you can use the ytickalign keyword for the Axis to move the position of the yticks.

using GLMakie

a = sin.(1:0.01:6); b = sin.(1:0.01:6) .+ randn.();

c = cos.(1:0.01:6) .+ 20

fig = Figure(resolution=(1200,700))
ax1 = fig[1,1] = Axis(fig, ytickalign=-5, yticklabelcolor=:blue)
ax2 = fig[1,1] = Axis(fig, yaxisposition=:right)
ax3 = fig[1,1] = Axis(fig, ytickalign=0, yticklabelcolor=:red)

plot!(ax1, a, color=:blue)
plot!(ax2, b)
plot!(ax3, c, color=:red)

hidexdecorations!(ax1)
hidexdecorations!(ax2)
linkxaxes!(ax1,ax2)
linkxaxes!(ax1,ax3)

This would produce this plot
image

3 Likes

thanks

thank you

1 Like