Unwanted clipping at corners of GLMakie 3d plot

Hi everyone,

I am using contour() from GLMakie to create a 3d level plot. My problem occurs when I zoom in; white triangles appear at the edges of the box, which cover my plot:

Does someone know how to fix this? I have been trying to play with the parameters of Axis3(), but I have not found a solution yet. Here is my code:

fig = Figure(size = (500, 600), dpi = 500)

xlabel = L"x/ξ"
ylabel = L"y/ξ"
zlabel = L"z/ξ"
titlesize = 20
xlabelsize = 20
ylabelsize = 20
zlabelsize = 20
xgridvisible = false
ygridvisible = false
zgridvisible = false

ax = Axis3(fig[1,1]; xlabel, xlabelsize, ylabel, ylabelsize, zlabel, zlabelsize, xgridvisible, ygridvisible, zgridvisible, 
                     aspect = (1,1,1), perspectiveness = 0.5, elevation = 0.5, azimuth = 4)

dom = (0, L*(1-2.0^(-N)))
ctr = contour!(dom, dom, dom, abs2.(ψ); levels = [0, 0.02, 0.04, 0.06, 0.08, 0.1], colormap = [:blue])

α = 0.8
limits!(ax, L/2 - α*L/2, L/2 + α*L/2, L/2 - α*L/2, L/2 + α*L/2, L/2 - α*L/2, L/2 + α*L/2)

display(fig)

Hi, and welcome to the Julia community!

Could you provide definitions for the missing variables (L, N, ψ) to make your code into a full MWE?

Sure, here is the creation of the array ψ, which defines the ring I plotted. L is the size of the box (without zoom), and N sets the grid size (2^N points per axis):

"""
    Dipole vortex core structure
"""
function VortexRingWaveFunction(x::Real, y::Real, z::Real, L::Real, R::Real)
    # Padé approximation constants
    a1 = 11/32
    b1 = (5-32*a1)/(48-192a1)
    a2 = a1*(b1-1/4)
    b2 = a2

    # Calculate variables
    r  = hypot(x-L/2, y-L/2)
    r1 = hypot(r-R, z-L/2)
    r2 = hypot(r+R, z-L/2)

    ρ1 = r1^2*(a1+a2*r1^2)/(1+b1*r1^2+b2*r1^4)
    ρ2 = r2^2*(a1+a2*r2^2)/(1+b1*r2^2+b2*r2^4)

    return √(ρ1*ρ2)
end

L = 32
N = 7
R = 5

x_list = collect(LinRange(0,L,2^N+1)[1:end-1])
y_list = collect(LinRange(0,L,2^N+1)[1:end-1])
z_list = collect(LinRange(0,L,2^N+1)[1:end-1])
ψ = zeros(ComplexF64, 2^N, 2^N, 2^N)
for (n, x) in enumerate(x_list)
    for (m, y) in enumerate(y_list)
        for (l, z) in enumerate(z_list)
            ψ[n,m,l] = VortexRingWaveFunction(x, y, z, L, R)
        end
    end
end

That looks like a bug for Axis3 in combination with contour. For a more minimal MWE, consider

using GLMakie

xs = ys = zs = -1.5:0.1:1.5
ws = [x^2 + y^2 + z^2 for x in xs, y in ys, z in zs]  # contour surfaces are spheres

fig = Figure()
ax = Axis3(fig[1, 1])
contour!(ax, ws, levels=[1.])
display(fig)

Note that this works fine with LScene instead of Axis3.

1 Like

@ffreyer

Thank you very much, yes this works great.

1 Like

Ah interesting, this happens when you scroll around. Maybe the contour has some kind of depth shift? It looks like the clip planes are applying too early somehow.