I am trying to plot the initial condition of some simulations I am running. The simulation is two-dimensional and the initial condition is composed of some hyperbolic tangents.
The issue is that when I plot this using contourf! from Makie I get an unexpected white band in the middle. My expectation is that everything that is white should be yellow (based on the accompanying picture below).
I’d guess this is an issue with whatever algorithm is generating the contours? There is not enough of a step in that area to generate contours? Something like that?
I’d appreciate any ideas on how to resolve this in Makie (i.e., I don’t want to go to another package or program to generate the plots).
Here is an MWE.
using CairoMakie, LinearAlgebra
begin
nx = ny = 10
xgrid = LinRange(0, 1, nx)
ygrid = LinRange(0, 1, ny)
ymin, ymax = 0.4, 0.6
steepness = 0.1
f(x,y) = (tanh((y - ymin) / steepness) - tanh((y - ymax) / steepness) - 1)
z = [f(x,y) for x in xgrid, y in ygrid]
end
begin
fig = Figure()
ax = Axis(fig[1, 1], xlabel = "x", ylabel = "y")
cof = contourf!(xgrid, ygrid, z, colormap=:plasma)
Colorbar(fig[1, 2], cof)
fig
end
I think a proper solution would be a fix of this Makie issue: the white region in the plot is a hole in the contour (you can see the grid when it’s not disabled by the theme). I’m surprised the extend... fill the hole.
I think that’s a bug, the last color in the poly subplot ends up as Inf for some reason, giving it the default NaN color which is transparent. When I manually set that color to the actual max value, I get the correct plot.
In this particular instance since the high side seems to be getting the Inf, maybe I could do something with cof.nan_color?
Maybe set it equal to the high side color of the colormap? I can “see” a high side color thing when I do cof.colormap but it is some type of Observable object and I don’t know how to access its contents.
Edit: Just tried cof.nan_color = to_colormap(cof.colormap[])[end] which does not appear to resolve the issue.
Thanks - that does work. But it adds the little extend high triangle to the colorbar. @jules demonstrated an example above of filling in the correct color without the little extend high triangle. Do you know how that was done? If not I will accept this and wait for the fix.