Thanks! this answer of @jules’s is closest to what I want to achieve: You scale the color scheme using the parameter
colorscale=ReversibleScale(conversion_func, inverse_conversion_func)
to contourf
. I paste a my sample code after incorporating the idea.
The only remaining issue is the labeling of the colorbar. The labels are still placed at a linear interval (it’s 50 in the following example), missing finer contour levels.
It would be nice if the tickmarks of Colorbar
tried to follow the levels specified as levels=[ . . .]
.
I’ll investigate.
using CairoMakie
xs = 0.0:1.0:10.0
ys = 0.0:1.0:7.0
func(x,y) = exp((x^2 + y^2)/20)
vals = func.(xs, ys')
levels = [2, 5, 10, 20, 50, 100, 200]
scaling = let thr = 2.0, lthr = log(thr)
function scale(x)
(x > thr) ? log(x) : ((x < -thr) ? -log(-x) : (x/thr)*lthr)
end
function invscale(x)
(x > lthr) ? exp(x) : ((x < -lthr) ? -exp(-x) : (x/lthr)*thr)
end
CairoMakie.ReversibleScale(scale, invscale)
end
fig = Figure()
ax = Axis(fig[1,1])
c = contourf!(ax, xs, ys, vals; colorscale=scaling
,levels = levels
,extendlow=:auto, extendhigh=:auto)
Colorbar(fig[1,2],c)
save("tmp2.png", fig)
j