Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add colorbar title (on top/bottom) #4387

Open
dmetivie opened this issue Sep 20, 2024 · 4 comments
Open

add colorbar title (on top/bottom) #4387

dmetivie opened this issue Sep 20, 2024 · 4 comments
Labels
enhancement Feature requests and enhancements Legend & Colorbar Makie Backend independent issues (Makie core)

Comments

@dmetivie
Copy link

dmetivie commented Sep 20, 2024

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 colobar title.
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

@dmetivie dmetivie added the enhancement Feature requests and enhancements label Sep 20, 2024
@ederag
Copy link

ederag commented Sep 20, 2024

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
Copy link
Member

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

@dmetivie
Copy link
Author

That would be great!

@asinghvi17
Copy link
Member

asinghvi17 commented Sep 20, 2024

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

@ffreyer ffreyer added Makie Backend independent issues (Makie core) Legend & Colorbar labels Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests and enhancements Legend & Colorbar Makie Backend independent issues (Makie core)
Projects
None yet
Development

No branches or pull requests

5 participants