Makie: Colorbar with the "High" and "Low" labels

nari
Fri, 14 Jul 2023 05:23:24 +0000
Visualization

When accompanying a heatmap with a color bar, the values at both ends themselves have no physical meaning, only the type and which direction they are used in are sometimes important. In that case, I would prepare a color bar like the following.

Currently, the size of the color bar, the coordinates to place the label and the font size are entered manually. Any comments on documentation or code I should read in order to specify some of these parameters and have the rest automatically optimized for position and size would be appreciated.

using CairoMakie
begin
    fig = Figure()
    ax = CairoMakie.Axis(fig[1,1], height=300, width=300)
    heatmap!(0:0.1:10π, 0:0.1:10π, [cos(x)+sin(y) for x in 0:0.2:20π, y in 0:0.2:20π],colormap=:viridis)
    ax1 = CairoMakie.Axis(fig[1,2], limits=(0,1,0,1),height=180, width=40)
    hidedecorations!(ax1)
    hidespines!(ax1)
    Colorbar(fig[1,2], colormap=:viridis, colorrange=(0,1),vertical = true, height=120, width=15, halign=:center, valign=:center,flipaxis = true, labelsize=20, labelpadding=10, ticksvisible=false, ticklabelsvisible=false)
    text!(ax1, 0.5,1.0, text="High", fontsize=20, align=(:center,:top))
    text!(ax1, 0.5,0.0, text="Low", fontsize=20, align=(:center,:bottom))
    resize_to_layout!(fig)
    display(fig)
end

3 posts - 2 participants