How to add Colorbar to heatmap!

I fail to grasp Makie’s doc on how to add a Colorbar, if the user use heatmap! instead of heatmap.

After reading the doc, I only know that this works

data = reshape(1:25, 5, 5)
fig, ax, hm = heatmap(data)
Colorbar(fig[:, end+1], hm)
save("temp.pdf", fig)

But if I want to add plots incrementally (the most frequent style), I don’t know how to:

f = Figure()
ax = Axis(f[1,1])
heatmap!(ax, data)
# how to add Colorbar???
save("temp.pdf", f)

ok, it seems this works

data = reshape(range(0, 1, 6), 2, 3)
f = Figure()
ax = Axis(f[1,1])
ret = heatmap!(ax, data)
Colorbar(f[1,2], ret)
save("temp.pdf", f)
1 Like