Makie Contourf Giving Incorrect Whitespace in Contours

TI36XPro
Wed, 06 Mar 2024 01:32:29 +0000
Visualization

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

10 posts - 4 participants