I would like to have the colorbar and the legend nicely aligned. Is there a way to perfectly align the top row of the legend with tick labels of the colorbar, and also the titles of legend and colorbar?
This is how it looks now
horizontal_colorbar(nothing, nothing)
horizontal_colorbar("label", "other label")
Here’s the code
function horizontal_colorbar(legend_title, colorbar_title)
fig = Figure()
ax = Axis(fig[2,1])
# Legend
markersizes = [5, 10, 15, 20]
group_size = [MarkerElement(marker = :circle, color = :black, strokecolor = :transparent,
markersize = ms) for ms in markersizes]
legend = Legend(fig,
group_size,
string.(markersizes),
legend_title,
nbanks = 2, orientation = :horizontal, tellwidth = false, tellheight = true)
fig[1, 1][1,1] = legend
# Colorbar
cb_attributes = (height = 18, width = Relative(0.7),
vertical = false,
valign = :center,
ticksize = 5,
ticklabelpad = 1.5)
cb = Colorbar(fig, limits=(-1, 1); cb_attributes...)
fig[1,1][1, 2][1,1] = cb
if !isnothing(legend_title)
Label(fig[1,1][1, 2][0, 1], "legend title", tellheight = true, tellwidth = false)
end
fig
end