Skip to content

Instantly share code, notes, and snippets.

@jkrumbiegel
Created September 9, 2021 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkrumbiegel/657efd5cf9bdf4891528d15cc6479d46 to your computer and use it in GitHub Desktop.
Save jkrumbiegel/657efd5cf9bdf4891528d15cc6479d46 to your computer and use it in GitHub Desktop.
makie axis bracket
function bracketlabel!(ax, label, mi, ma, axoffset, bracketwidth, labeloffset)
bracketpoints = lift(ax.finallimits, ax.scene.px_area) do lims, px_area
x = minimum(lims)[1]
pmin = Makie.project(ax.scene, Point2f(x, mi))
pmax = Makie.project(ax.scene, Point2f(x, ma))
ps = Point2f[
pmin,
pmin - Point2f(bracketwidth, 0),
pmax - Point2f(bracketwidth, 0),
pmax
] .- Point2f(axoffset, 0)
ps .+ Point2f(px_area.origin)
end
labelpoint = lift(bracketpoints, labeloffset) do ps, loff
(ps[2] + ps[3]) / 2 - Point2f(loff, 0)
end
s = MakieLayout.get_topscene(ax.parent)
text!(s, label, position = labelpoint, rotation = pi/2, align = (:center, :bottom))
lines!(s, bracketpoints)
end
f = Figure()
ax, hm = heatmap(f[1, 1], randn(20, 20))
ax.yticklabelspace = 120
bracketlabel!(ax, "group 1", 1, 5, 40, 5, 5)
bracketlabel!(ax, "group 2", 6, 10, 40, 5, 5)
bracketlabel!(ax, "group 3", 11, 15, 40, 5, 5)
bracketlabel!(ax, "group 4", 16, 20, 40, 5, 5)
bracketlabel!(ax, "supergroup1", 1, 10, 90, 5, 5)
bracketlabel!(ax, "supergroup1", 11, 20, 90, 5, 5)
f
@jkrumbiegel
Copy link
Author

grafik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment