Julia Makie merge/overlay plots

I have two heatmaps that I would like to merge to get the amount of two quantities at once. The idea is that one level is green shaded, the other is red, thus the more the resulting plot is “Cinnamon” the more the two amounts are equal in value.
Something like this:

grid1 = rand(Float16, 5, 5)
grid2 = rand(Float16, 5, 5)
using CairoMakie
using ColorSchemes 
xs = collect(range(1,stop=5)) 
ys = collect(range(1,stop=5)) 
fig1, ax1, hm1 = heatmap(xs, ys, grid1,  colormap = :greens)
ax = Axis(fig1[1, 1], xlabel = "X", ylabel = "Y")
Colorbar(fig1[:, end+1], hm1)
fig2, ax2, hm2 = heatmap(xs, ys, grid2,  colormap = :reds)
ax = Axis(fig2[1, 1], xlabel = "X", ylabel = "Y")
Colorbar(fig2[:, end+1], hm2)

Plot 1:

Plot 2:


Here the merge has been done by overlaying plot 2 with a 50% transparency. Perhaps there is a better Julia way of making this kind of merged plots…
Thank you

1 Like

Howdy again. Maybe it would make sense to just do the computation ahead of time, and then display the resulting heatmaps?

using CairoMakie

# Data
Z_green, Z_red = rand(3, 4), rand(3, 4)
Z_diff = @. 1.0 - abs(Z_red - Z_green)

# Plot
fig = Figure()

Zs = Z_green, Z_red, Z_diff
colormaps = :reds, :greens, :heat

for (i, (Z, colormap)) ∈ enumerate(zip(Zs, colormaps))
    ax = Axis(fig[1, 2*i - 1]; width=250, height=250)
    hm = heatmap!(ax, permutedims(Z); colorrange=(0, 1), colormap)
    Colorbar(fig[1, 2*i], hm)




Thank you. Yes, probably it is better to rearrange the data first. I used a more containing scheme (roma) to get a better sense of the shift in data: