Plots.jl GR add space between the colorbar and the colorbar_title

Hi, how can I control the space between the colorbar and the colorbar_title?

using Plots
p = heatmap(rand(100, 100);
    colorbar_title = "colorbar title",
    thickness_scaling = 1.6,
)
savefig(p, "test.png")

test

Im using:
julia 1.6.1
Plots v1.19.3
GR v0.58.0

Thanks!

2 Likes

Based on a quick glance at the code here, you’d expect to be able to play around with:

    :colorbar_titlefontsize => 10,
    :colorbar_title_location => :center,           # also :left or :right
    :colorbar_titlefontfamily => :match,
    :colorbar_titlefonthalign => :hcenter,
    :colorbar_titlefontvalign => :vcenter,
    :colorbar_titlefontrotation => 0.0,

but it didn’t work for me. Perhaps another backend would help: plotly() sometimes has more options for tweaking than gr(). Inserting a line break in the title \n also didn’t work.

The best I can do for now is to resize the image. See the size argument. But then your thickness requirement is also diluted a little. So it’s not too different from reducing thickness_scaling. In other words, I can’t help very much, hopefully someone else will!

plot(st=:heatmap,
    rand(100, 100),
    colorbar_title="colorbar title",
    thickness_scaling=1.6,
    size=(1000,1000)
)
1 Like
using Plots
p = heatmap(rand(100, 100);
    colorbar_title = " \ncolorbar title",
    thickness_scaling = 1.6,
    right_margin = 2Plots.mm,
)

image

Warning: The first blank of " \ncolorbar title" is not the ordinary blank ' '.

6 Likes

Oh! I guess the linebreak is stripped if there is no string before it, so "\nTitle" fails but " \nTitle" works. Neat.

1 Like

Clever, thanks!!!