One colorbar for multiple axes

Precision: limits have to be set for both the heatmaps and the colorbar.
Here is a more detailed example:

using CairoMakie
# define the maps
n_rows = 2
n_cols = 5
maps = [rand(5,5) .* (i_row * 10 + i_col) for i_row in 1:n_rows, i_col in 1:n_cols]
# get global extrema
extremas = map(extrema, maps)
global_min = minimum(t->first(t), extremas)
global_max = maximum(t->last(t), extremas)
# these limits have to be shared by the maps and the colorbar
clims = (global_min, global_max)

let
	fig = Figure()
	for i_row in 1:n_rows, i_col in 1:n_cols
		ax =  Axis(fig[i_row, i_col])
		heatmap!(ax, maps[i_row, i_col]; colorrange=clims)
	end
	cb = Colorbar(fig[:, n_cols + 1]; limits=clims)
	fig
end

It would be nice to just pass an iterable of heatmaps to colorbar to automate this process ?

2 Likes