Colorbar_title position & orientation

When dealing with several 2.5 d plots at the same time, it’s nice to indicate what the colorbar stands for.
To do so, we have the colorbar_title attribute, now even supported by GR. I assume, with long titles in mind, it puts the colorbar_title in vertical orientation right next to the colorbar, e.g. this example:
cbtitle

This is not always the most legible way. Especially with shorter titles, it would be nice to be able to tell colorbar_title to be in :horizontal orientation.
On top of this, it would be great to have a second line just above the colorbar to annotate units. The units could even have a bit smaller font szie than the title text.
So what I am looking for is something like this:
CBT_MyTitle

Is some of this already implemented and I have overlooked it?
What would be a robust way to place the colorbar_title in horizontal orientation ontop of the colorbar?
With robust I mean a better response to the positioning than me using annotate = (x,y,"MyCBTitle")
Which is not so useful when later composing plots with @layout.
Any suggestions are very welcome.

Hello, I know that you are looking for something that works with Plots. I do not have a solution with Plots, however I can do what you are asking for with Gnuplot.jl. Take a look at the examples(and yes you need to play around a little with some parameters, but not much).

  1. Single plot:
using Gnuplot, Random
Random.seed!(123)
test = rand(50,50)
@gp "set auto fix" "set size square" :-
@gp :- test "w image notit"  """set cblabel "CBTitle \\n (my unit)" """ :-
@gp :- "set cblabel  offset -6.5, 10 font ',8' textcolor lt 3 rotate by 0" :-
@gp :- palette(:plasma) :-
@gp :- "set tmargin at screen 0.90"
save(term = "pngcairo size 400,400", output = "colorbar_labels_single.png")

colorbar_labels_single
2. Multiplot

1 Like
using Gnuplot, Random
Random.seed!(123)
test = rand(50,50)
@gp "set multiplot layout 1,2"
# on top
@gp :- 1 "set auto fix" "set size square" :-
@gp :- test "w image notit"  """set cblabel "CBTitle \\n (my unit)" """ :-
@gp :- "set cblabel offset -6.5, 10 font ',8' textcolor lt 3 rotate by 0" :-
@gp :- "set tmargin at screen 0.85" :-
# on the side
@gp :- 2 "set auto fix" "set size square" :-
@gp :- test "w image notit"  """set cblabel "CBTitle (my unit)" """
@gp :- "set cblabel offset 0, 0 font ',8' textcolor lt 4 rotate by 90" :-
@gp :- palette(:viridis) :-
@gp :- "set rmargin at screen 0.9"
save(term = "pngcairo size 800,400", output = "colorbar_labels_layout.png")

Thanks for your contribution.
And a nice reminder of why I like gnuplot.

However, I’m still looking for a solution with Plots and GR.

Is there a way to get the colorbar a subplot so it could be rearanged with @layout?

Perhaps on the lines of the following.
For the plot p in:

p = plot(rand(100, 100), seriestype = :histogram2d)

I am looking for a handle on the colorbar:

cb = p[1][1].colorbar

So I’d be able to put it where I want

an = annotate(text("CBT"))

l = @layout [             an{0.1h}
               heatmap       cb        ]

plot(p, cb, an, layout = l)

One way:

using Measures, Plots; gr()

z = rand(100, 100)
l = @layout [a{0.95w} [b{0.03h}; c]]
p1 = heatmap(axes(z,1), axes(z,2), z, cbar=false)
p2 = plot([NaN], lims=(0,1), framestyle=:none)
annotate!(-0.2, -0.5, text("Random\n[m/s]", 9, "Computer Modern"))
p3 = heatmap([NaN;;], framestyle=:none, clims=extrema(z), cbar=true)
plot(p1,p2,p3, layout=l, margins=0mm)

1 Like