Makie: open-ended contouring levels for contourf?

ryofurue
Sat, 18 Nov 2023 16:25:42 +0000
Visualization

This thread discusses how to limit the contouring values. My question is a followup on that: How to paint all values above and below the limits and coordinate with the colorbar?

The first image below is what I need and the second image is what my little Julia program (shown at the very end) produces. Please focus on the colorbar of the first image: the (-Inf, -0.5) range is painted in the lowest extreme color of viridis and the (0.5, Inf) range is painted in the highest extreme color, and the colorbar has little triangles at the ends.

The Makie:Colorbar tutorial shows how to use lowclip and highclip, so there is a great hope, but I don’t know how to limit the color range of the palette (viridis, in the present case) and reserve the highest and lowest extreme colors for the triangles. (Okay, I could create my own version of viridis removing the extremities and use them for the lowclip and highclip colors, but that would be super tedious . . .)

In any case, this kind of open-ended contouring is so common (at least in my field) that it would be nice if there be a half-automatic solution.

I’ve tried levels = vcat(-Inf, -0.5:0.1:0.5, Inf), which I thought would be an obvious solution but which resulted in error.

using CairoMakie

func(x,y) = cos(2π*x/100) * sin(2π*y/100)

xs = 0:10:100
ys = 0:10:100
arr = func.(xs, reshape(ys,1,:))

fig = Figure()
ax = Axis(fig[1,1])
tightlimits!(ax)
c = contourf!(ax, xs, ys, arr; levels=-0.5:0.1:0.5)
Colorbar(fig[1,2], c)
save("tmp2.png", fig)

3 posts - 2 participants