I cannot seem to find good documentation for how to make a horizontal color bar in CairoMakie. I found the vertical=false option, but I cannot seem to create a gap between the color bar and the plot (see example below) and it is not playing well with the plot title. Anyone have a MWE of a horiztonal color bar, with a gap, and a plot title?
Here is a brute force and ignorance method from me:
fig = Mke.Figure()
ax1 = Mke.Axis(fig[2:5, 2], title="Spatial Distribution of Grant Funding", titlesize=10.0f0,
subtitle=" ", subtitlesize=7.0f0,
#=limits=(met.xaxismin, met.xaxismax, met.yaxismin, met.yaxismax),=#
#xlabel="Easting", xlabelsize=7.0f0, xtickformat="{:.0f}", xticklabelsize=6.0f0,
#ylabel="Northing", ylabelsize=7.0f0, ytickformat="{:.0f}", yticklabelsize=6.0f0,
xlabelvisible=false, ylabelvisible=false, xticklabelsvisible=false, yticklabelsvisible=false,
xticksvisible=false, yticksvisible=false, ygridvisible=false, xgridvisible=false,
aspect=Mke.DataAspect())
viz!(ax1, longt.geometry, color=longt.col, colormap=:lajolla, segmentcolor="black",
showsegments=true, segmentsize=0.3f0, colorrange=log10.(cr))
Mke.Colorbar(fig[6, 2], limits=cr, colormap="lajolla", scale=log10, tickformat=t_ft,
ticklabelsize=7.0f0, label=ax_lab, labelsize=8.0f0, valign=:top, vertical=false, flipaxis=false)
ax2 = Mke.Axis(fig[2:5, 1], title="Top Local Authority Recipients", titlesize=10.0f0,
subtitle=pstitle, subtitlesize=7.0f0,
yticks=(1:nticks, plotdf.newLocalAuthority), xtickformat=t_ft,
limits=(cr, (0.5, nticks + 0.5)), xscale=log10, xticklabelsize=10.0f0, ygridvisible=false, xgridvisible=false,
yticklabelsize=8.0f0, xlabel=ax_lab, xlabelsize=8.0f0,
yticksvisible=false, yminorticks=0.5:1:nticks+0.5, yminorticksvisible=true, yminorticksize=3)
Mke.barplot!(ax2, plotdf.nla, plotdf.rat, direction=:x, color=plotdf.rat, fillto=minimum(cr),
colormap=:lajolla, colorrange=cr, colorscale=log10, strokecolor=:black, strokewidth=1)
Mke.vlines!(ax2, 1, ymax=1, color=:red, linestyle=:dash)
Mke.Label(fig[0, :], "Comparative Share of National Lottery Grant Funding\nAdjusted for Population Size", font=:bold, fontsize=16.0f0)
Mke.Label(fig[1, :], stitle, fontsize=12.0f0)
Mke.Legend(fig[6, 1], [Mke.LineElement(color=:red, linestyle=:dash)], ["England Average"], labelsize=7.0f0, tellheight=false,
tellwidth=false, halign=:center, valign=:top, orientation=:horizontal, margin=(5, 5, 5, 5), height=30.0f0)
Mke.save("tmp.pdf", fig)
I place each element into a notional 6x2 grid of elements on the page. There are two plots that fill position (2:5, 1) and (2:5, 2) on this grid. The colorbar goes under the right of these in position (6, 2) on the grid.
Iām sure there is a more elegant way!
Like this?
f = Figure()
Colorbar(f[1, 1], vertical = false, label = "Photometric g-band Epochs")
ax = Axis(f[2, 1])
rowgap!(f.layout, 1, 5)
f
3 Likes
Yes. I think I had some psychological block in making the plot f[2,1] rather than f[1,1]. Thank you!