Makie Contourf Giving Incorrect Whitespace in Contours

Hello,

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

See maybe extendlow and/or extendhigh in contourf.

julia> fig, ax, cof = contourf(xgrid, ygrid, z, extendlow=:cyan, extendhigh=:magenta)
julia> Colorbar(fig[1, 2], cof)
julia> fig

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.

julia> cof.plots[1].color[]
21-element Vector{Float64}:
 -0.9327735900878906
 -0.9327735900878906
 -0.799637496471405
 -0.799637496471405
 -0.6665014028549194
 -0.6665014028549194
 -0.5333653688430786
 -0.5333653688430786
 -0.400229275226593
 -0.400229275226593
 -0.2670931816101074
 -0.2670931816101074
 -0.1339571177959442
 -0.1339571177959442
 -0.000821039080619812
 -0.000821039080619812
  0.1323150396347046
  0.1323150396347046
  0.2654511034488678
  0.2654511034488678
 Inf

The bug is that is_extended_low and is_extended_high are marked true, where they shouldn’t Makie.jl/src/basic_recipes/contourf.jl at master · MakieOrg/Makie.jl · GitHub.

I’m taking a look, I guess it’s worth opening an issue.

EDIT: opened contourf bug · Issue #3683 · MakieOrg/Makie.jl · GitHub, fix tbd in fix Inf value on non-extended case by t-bltg · Pull Request #3684 · MakieOrg/Makie.jl · GitHub.

Thanks for doing that.

Do you have any near-term fix suggestions though?

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.

Can you share how you did that manual fix?

You can use extendhigh=:auto.

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.

Thanks for all the replies. I manually fixed it by doing cof.plots[1].color[][end] = 1.0.