Created
September 9, 2021 08:12
-
-
Save jkrumbiegel/657efd5cf9bdf4891528d15cc6479d46 to your computer and use it in GitHub Desktop.
makie axis bracket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Author
jkrumbiegel
commented
Sep 9, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment