Aliasing with Makie contourf

Is there a way to get rid of the aliasing in the contourf! lines in the following example?

using CairoMakie

function testcontourf()
    xs = LinRange(0, 10, 100)
    ys = LinRange(0, 10, 100)
    zs = [cos(x) * sin(y) for x in xs, y in ys]

    f = Figure()
    ax = Axis(f[1, 1])

    c = contourf!(ax, xs, ys, zs, levels = 50)
    Colorbar(f[1, 2], c)
    display(f)
end

testcontourf()

In actuality, I’d prefer to get the plot to look the way it does if I double the contourf! call, and eliminated the lines that show up.

function testcontourf_double()
    xs = LinRange(0, 10, 100)
    ys = LinRange(0, 10, 100)
    zs = [cos(x) * sin(y) for x in xs, y in ys]

    f = Figure()
    ax = Axis(f[1, 1])

    c = contourf!(ax, xs, ys, zs, levels = 50)
    c = contourf!(ax, xs, ys, zs, levels = 50)
    Colorbar(f[1, 2], c)
    
    display(f)
end

testcontourf_double()

Which results in this image without the lines.

So, you maybe just want a heatmap? there is also the option of interpolate=true, to get smooth interpolation between data points

Neat, I didn’t know about the interpolate option for heatmap!. That helps. I’m guessing the lines are just a result of the way Makie plots each level?

Well, if you plot lines too closely together they will alias… You would need some global anti aliasing pre-processing filter on top of that, which usually isn’t used in e.g. CairoMakie, which aliases each object (e.g. the lines) separately for optimal quality.

A global aliasing filter is usually not preferred if possible, since it has much less information and introduces new artifacts that way.

Ok, that makes sense. Either way, thanks for your work on Makie! It’s my go-to plotting library in julia

1 Like