Makie: row 2 colorbar without affecting row 1

ryofurue
Tue, 14 Nov 2023 14:28:13 +0000
Visualization

I’m plotting two equal-sized graphs on the first row (fig[1,1] and fig[1,2]) and a single contour plot on the second row (fig[2,1]). My question is, how do you plot the colorbar for the contour plot? What is the standard solution?

All tutorials I’ve found so far uses a separate column for the colorbar. (I’m linking a relevant example at the end of this message.) That column is fig[2,2] for my case. So, as soon as I add the colorbar, it changes the size of the graph above the colorbar (fig[1,2]).

Below is a sample program that illustrates the problem.

using CairoMakie

func(x,y) = cos(x)*sin(y)

fig = Figure()
ax11 = Axis(fig[1,1])
ax12 = Axis(fig[1,2])
ax21 = Axis(fig[2,1]; aspect=1)

xs = -pi:(pi/16):pi
ys = xs

lines!(ax11, xs, sin.(xs))
lines!(ax12, xs, cos.(xs))
co = contourf!(ax21, xs, ys, func.(xs, reshape(ys,1,:)) )
Colorbar(fig[2,2], co) # <- messes up the layout

save("tmp.pdf", fig)

https://docs.makie.org/stable/tutorials/aspect-tutorial/

7 posts - 3 participants