Multiple colobars

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) and I get as far as this:

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

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

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

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

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

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?

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)

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

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

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.
p2  = contour!(ax2, x, y, z2, colormap=:roma)
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

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

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

Done

1 Like