# How to add Colorbar to heatmap!

**URL:** <https://discourse.julialang.org/t/how-to-add-colorbar-to-heatmap/134736>\
**Category:** Specific Domains\
**Tags:** makie\
**Created:** [December 26, 2025, 2:08am UTC](https://discourse.julialang.org/t/how-to-add-colorbar-to-heatmap/134736 "2025-12-26T02:08:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Post date:** [December 26, 2025, 2:08am UTC](https://discourse.julialang.org/t/how-to-add-colorbar-to-heatmap/134736/1 "2025-12-26T02:08:24Z")

</div>

I fail to grasp Makie’s [doc](https://docs.makie.org/stable/reference/plots/heatmap#Colorbar-for-single-heatmap) on how to add a Colorbar, if the user use `heatmap!` instead of `heatmap`.

After reading the doc, I only know that this works

```julia
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:

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

```

---

<div class="post-metadata">

**Author:** ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Post date:** [December 26, 2025, 2:29am UTC](https://discourse.julialang.org/t/how-to-add-colorbar-to-heatmap/134736/2 "2025-12-26T02:29:48Z")

</div>

ok, it seems this works

```julia-auto
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)

```

---

<div class="post-metadata">

**Author:** ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)\
**Post date:** [January 4, 2026, 8:33am UTC](https://discourse.julialang.org/t/how-to-add-colorbar-to-heatmap/134736/3 "2026-01-04T08:33:37Z")

</div>

Yep `ret` here is the `plt` in `fig, ax, plt`
