# Multiple colobars

**URL:** <https://discourse.julialang.org/t/multiple-colobars/116970>\
**Category:** Visualization\
**Tags:** colorbar, cairomakie, contouring\
**Created:** [July 12, 2024, 2:10pm UTC](https://discourse.julialang.org/t/multiple-colobars/116970 "2024-07-12T14:10:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArneSpang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arnespang/32/203822_2.png) [@ArneSpang](https://discourse.julialang.org/u/ArneSpang)\
**Post date:** [July 12, 2024, 2:10pm UTC](https://discourse.julialang.org/t/multiple-colobars/116970/1 "2024-07-12T14:10:20Z")

</div>

I am trying to make a plot with a heatmap in the background and contour plot of a different field on top. I could steal some ideas from this thread ([Overlay a contour over a heatmap - #8 by lazarusA](https://discourse.julialang.org/t/overlay-a-contour-over-a-heatmap/53586/8)) and I get as far as this:

```julia
using CairoMakie
x = y = 1:0.2:20
f1(x,y) = (x + 2y^2) * abs(sin(y) + cos(x))
f2(x,y) = -10(x + 2y^2) * abs(sin(x) + cos(y))
z1 = [f1(x,y) for x in x, y in y]
z2 = [f2(x,y) for x in x, y in y]
fig = Figure(resolution=(350,300), fontsize = 14)
ax1 = Axis(fig, aspect = 1, xlabel = "x", ylabel = "y")
p1 = heatmap!(ax1, x, y, z1, colormap=:plasma)
p2 = contour!(ax1, x, y, z2, colormap=:roma)
fig[1,1] = ax1
fig

```

![Screenshot from 2024-07-12 16-08-09](https://global.discourse-cdn.com/julialang/original/3X/3/2/32e3d0470f2d79b31f6f69d550d2731ee8c7fe04.png)

But I don’t manage to get two colorbars. If I try this:

```julia
cb1 = Colorbar(fig, p1, width = 10, height = Relative(0.8), ticklabelsize = 10, tickalign = 1)
cb2 = Colorbar(fig, p2, width = 10, height = Relative(0.8), ticklabelsize = 10, tickalign = 1)

```

I get:  
ERROR: Multiple colormaps found for plot MakieCore.Text

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [July 12, 2024, 3:31pm UTC](https://discourse.julialang.org/t/multiple-colobars/116970/2 "2024-07-12T15:31:24Z")

</div>

I would do two axis ☹ (on top of each other) and then call a colorbar for each.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [July 12, 2024, 3:33pm UTC](https://discourse.julialang.org/t/multiple-colobars/116970/3 "2024-07-12T15:33:16Z")

</div>

Hm the Text suggests this is because of the labels of the contour plot, which aren’t made visible here. Sounds like a bug

---

<div class="post-metadata">

**Author:** ![ArneSpang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arnespang/32/203822_2.png) [@ArneSpang](https://discourse.julialang.org/u/ArneSpang)\
**Post date:** [July 12, 2024, 3:49pm UTC](https://discourse.julialang.org/t/multiple-colobars/116970/4 "2024-07-12T15:49:35Z")

</div>

I tried making `ax2` like I make `ax1` and then assign `p2` to `ax2` but then I still get the same error.  
Also, how would I then shift the axis on top of each other?

```julia
x = y = 1:0.2:20
f1(x,y) = (x + 2y^2) * abs(sin(y) + cos(x))
f2(x,y) = -10(x + 2y^2) * abs(sin(x) + cos(y))
z1 = [f1(x,y) for x in x, y in y]
z2 = [f2(x,y) for x in x, y in y]
fig = Figure(resolution=(350,300), fontsize = 14)
ax1 = Axis(fig, aspect = 1, xlabel = "x", ylabel = "y")
ax2 = Axis(fig, aspect = 1, xlabel = "x", ylabel = "y")
p1 = heatmap!(ax1, x, y, z1, colormap=:plasma)
p2 = contour!(ax2, x, y, z2, colormap=:roma)
cb1 = Colorbar(fig, p1, width = 10, height = Relative(0.8), ticklabelsize = 10, tickalign = 1)
cb2 = Colorbar(fig, p2, width = 10, height = Relative(0.8), ticklabelsize = 10, tickalign = 1)

```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [July 12, 2024, 3:58pm UTC](https://discourse.julialang.org/t/multiple-colobars/116970/5 "2024-07-12T15:58:27Z")

</div>

Could you delete the text plot from the contour plot and see if it works then? Maybe `delete!(cont.plots[2)` or with `deleteat!`, not sure which index it has

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [July 12, 2024, 4:09pm UTC](https://discourse.julialang.org/t/multiple-colobars/116970/6 "2024-07-12T16:09:06Z")

</div>

oh, this is an actual issue (please open one!) with `contour`:

```julia
ERROR: Multiple colormaps found for plot MakieCore.Text{Tuple{Vector{Point{2, Float32}}}}, please specify which one to use manually. Please overload `Makie.extract_colormap(::MakieCore.Text{Tuple{Vector{Point{2, Float32}}}})` to allow for the automatical creation of a Colorbar.

```

```Julia
p2 = contour!(ax2, x, y, z2, colormap=:roma)

```

```julia
julia> p2.
alpha color colormap colorrange colorscale
depth_shift dim_conversions enable_depth fxaa highclip
inspectable inspector_clear inspector_hover inspector_label joinstyle
labelcolor labelfont labelformatter labels labelsize
levels linecap linestyle linewidth lowclip
miter_limit model nan_color overdraw space
ssao transformation transparency visible

```

p2 doesn’t have `plots` entry @jules

---

<div class="post-metadata">

**Author:** ![ArneSpang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arnespang/32/203822_2.png) [@ArneSpang](https://discourse.julialang.org/u/ArneSpang)\
**Post date:** [July 15, 2024, 8:56am UTC](https://discourse.julialang.org/t/multiple-colobars/116970/7 "2024-07-15T08:56:17Z")

</div>

So should I open an issue about this on the Makie Github?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [July 15, 2024, 9:07am UTC](https://discourse.julialang.org/t/multiple-colobars/116970/8 "2024-07-15T09:07:51Z")

</div>

Yes if it doesn’t exist already, that would be nice

---

<div class="post-metadata">

**Author:** ![ArneSpang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arnespang/32/203822_2.png) [@ArneSpang](https://discourse.julialang.org/u/ArneSpang)\
**Post date:** [July 15, 2024, 10:15am UTC](https://discourse.julialang.org/t/multiple-colobars/116970/9 "2024-07-15T10:15:53Z")

</div>

Done

> <https://github.com/MakieOrg/Makie.jl/issues/4036>
>
> \- \[x\] are you running newest version (version from docs) ? - yes
> \- \[x\] can you …reproduce the bug with a fresh environment ? (\`\]activate --temp; add Makie\`) - yes
> \- \[x\] What platform + GPU are you on? - Ubuntu 22.04 + NVIDIA RTX A4000
> 
> I was trying to put a contour plot over a heatmap (of a different dataset) and have two colorbars. But I cannot create one for the contour plot. After asking about this (https://discourse.julialang.org/t/multiple-colobars/116970/6), @lazarusA noticed that the \`plots\` entry is not present in the contour object. MWE and error message below:
> 
> \`\`\`julia
> using CairoMakie
> x = y = 1:0.2:20
> f1(x,y) = (x + 2y^2) \* abs(sin(y) + cos(x))
> z1 = \[f1(x,y) for x in x, y in y\]
> fig = Figure(resolution=(350,300), fontsize = 14)
> ax1 = Axis(fig, aspect = 1, xlabel = "x", ylabel = "y")
> p1 = contour!(ax1, x, y, z1, colormap=:roma)
> cb1 = Colorbar(fig, p1, width = 10, height = Relative(0.8), ticklabelsize = 10, tickalign = 1)
> \`\`\`
> 
> \`\`\`julia
> ERROR: Multiple colormaps found for plot MakieCore.Text{Tuple{Vector{Point{2, Float32}}}}, please specify which one to use manually. Please overload \`Makie.extract\_colormap(::MakieCore.Text{Tuple{Vector{Point{2, Float32}}}})\` to allow for the automatical creation of a Colorbar.
> \`\`\`
