MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.42k stars 313 forks source link

add `colorbar` title (on top/bottom) #4387

Open dmetivie opened 1 month ago

dmetivie commented 1 month ago

Feature description

It would be cool to have the option to place a title (or label, not sure of the most appropriate name) on top (and why not bottom) of vertical colorbar. With Matplotlib I would use clb.ax.set_title. This is useful for short title (like units).

So far, the Julia community gave me two tricks on Zulip to do it in simple situation by adding a label manually on top Label(fig[0,2], text = "Hello") or creating an empty figure on top.

However, in complex situation this does not work simply (I typically use GeoMakie.jl and due to spacing issues I have to use rowgap! which move the added colobartitle. In any case, a simple title option would be better. Not sure how it would work with horizontal colorbar.

For plot types, please add an image of how it should look like

Here is an example with Matplotlib (and Cartopy), the title place the hPa on top of the colobar. image

ederag commented 1 month ago

Or create a label_position attribute (maybe without the underscore to match the rest of the API) to move the label to a specific position: :right (default for the vertical colorbar), :left, :bottom, and :top (the latter being desired here) ? That would work with an horizontal colorbar as well, with clear meaning ?

jkrumbiegel commented 1 month ago

colorbar already has a flip option which also flips the label, so that would also factor into it I guess

dmetivie commented 1 month ago

That would be great!

asinghvi17 commented 1 month ago

If you want to get around spacing issues, here's a solution for the interim:

using CairoMakie, GeoMakie
fig = Figure(size = (400, 600))
a1, p1 = meshimage(fig[1, 1], -180..180, -90..90, rotr90(GeoMakie.earth()); axis = (; type = GeoAxis, dest = "+proj=moll"))
a2, p2 = meshimage(fig[2, 1], -180..180, -90..90, rotr90(GeoMakie.earth()); axis = (; type = GeoAxis, dest = "+proj=ortho"))
# now define the colorbar
cb_cell = fig[1:2, 2] = GridLayout() # treat the colorbar-and-label system as a single grid cell
rowgap!(cb_cell, 5) # set this or don't
cb = Colorbar(cb_cell[2, 1], #= ... =#)
cb_label = Label(cb_cell[1, 1], "hPa"; tellheight = true, tellwidth = false)
fig

download-14