Colorbar title placement in makie

I’m trying to make a figure which features a horizontal colorbar. I would like the title of the colorbar to be placed directly to the right of the colorbar, instead of above/below.
I’ve seen this post but using this messed up the layout of the rest of the figure.

Is that possible? Or is there a simple fix that does not affect the curent layout?

How did it mess up the layout of the rest of the figure?

You could alternatively try halign = :left, width = 0. I’m not 100% sure but I’d predict that this leaves the label location as is, but doesn’t affect the layout because the element now looks like it doesn’t have any width.

So the figure has 3 columns and the colorbar is created this way:

    cb = Colorbar(f[2, 1:3], hm, label="Label", width = 300, labelsize = ftsz, ticklabelsize = ftsz, vertical=false, valign=true, flipaxis = true )

To mimic what was done in the post, I tried:

    Label(f[2, 4, Right()], "Label")

but this created a 4th column which squeezed the above/below rows.

Ah, the Right side should be in the same column where your colorbar is. So f[2, 3, Right()]. Otherwise you add a new full column, as you’ve noted. Right refers to the protrusion or gap space on the right side of that layout column.

1 Like

Ah nice, thank you!
What is the best strategy to reduce the space between the colorbar and the label ?
It’s currently very much to the right.

It’s easier if you give example code with an image, I don’t know what “very much to the right” looks like :slight_smile:

This is basically what Label(f[2, 3, Right()], "label", halign = :left) did:


Now the aim would be to get label adjacent to the colorbar without disturbing the position of the three above panels.

Ah, ok I see, the problem is that the colorbar spans across three columns but only uses part of that width. The protrusion space starts at the actual end of column 3 though, so there’s a gap.

Use a nested gridlayout at the position where the colorbar is now, then put the colorbar at [1, 1] in that layout and the label at [1, 1, Right()]. The column width of that inner layout will shrink to the colorbar’s width, making the label correctly positioned while still leaving the colorbar centered. If you put the label in column 2 of the nested layout, the colorbar would not be centered anymore.

1 Like