Break axis in Makie

Here’s a possible implementation, although it uses some rather internal things:

f = Figure()

lims = Node(((0.0, 1.3), (7.6, 10.0)))

g = f[1, 1] = GridLayout()

ax_top = Axis(f[1, 1][1, 1], title = "Broken Y-Axis")
ax_bottom = Axis(f[1, 1][2, 1])

on(lims) do (bottom, top)
    ylims!(ax_bottom, bottom)
    ylims!(ax_top, top)
    rowsize!(g, 1, Auto(top[2] - top[1]))
    rowsize!(g, 2, Auto(bottom[2] - bottom[1]))
end

hidexdecorations!(ax_top, grid = false)
ax_top.bottomspinevisible = false
ax_bottom.topspinevisible = false

linkxaxes!(ax_top, ax_bottom)
rowgap!(g, 10)

angle = pi/8
linelength = 30

segments = lift(
        @lift($(ax_top.elements[:yaxis].attributes.endpoints)[1]),
        @lift($(ax_bottom.elements[:yaxis].attributes.endpoints)[2]),
        @lift($(ax_top.elements[:yoppositeline][1])[1]),
        @lift($(ax_bottom.elements[:yoppositeline][1])[2]),
    ) do p1, p2, p3, p4
    ps = Point2f0[p1, p2, p3, p4]

    map(ps) do p
        a = p + Point2f0(cos(angle), sin(angle)) * 0.5 * linelength
        b = p - Point2f0(cos(angle), sin(angle)) * 0.5 * linelength
        (a, b)
    end
end

linesegments!(f.scene, segments)

scatter!(ax_top, randn(100, 2) .* 0.5 .+ 9)
scatter!(ax_bottom, randn(100, 2) .* 0.2 .+ 0.25)

notify(lims)

f
7 Likes