Double y-axis on left and right side of plot in Makie.jl

Viewed 586

I want to make a double yaxis in Makie, so that one y axis on the left and has its own values, and the other is on the right and has its own values, while they share x axis.

For example to do this in PyPlot one would follow https://matplotlib.org/gallery/api/two_scales.html and get

enter image description here

How is this done in Makie.jl? If the answer could say how to also color the axis, then double points from me!

1 Answers

With CairoMakie 0.3.7, AbstractPlotting 0.13.8:

using CairoMakie
using CairoMakie.AbstractPlotting.MakieLayout

scene, layout = layoutscene(resolution = (600, 400))
ax1 = layout[1, 1] = LAxis(scene, yticklabelcolor = :blue, ytickcolor = :blue)
ax2 = layout[1, 1] = LAxis(scene, yticklabelcolor = :red, ytickcolor = :red, backgroundcolor = :transparent)

hidexdecorations!(ax2)
hidespines!(ax2)
yaxis_right!(ax2)
linkxaxes!(ax1, ax2)

lines!(ax1, 0..10, sin, color = :blue)
lines!(ax2, 0..10, x -> 5cos(x), color = :red)

scene

example

Related