Wrong image when trying to create a simple 3d surface

I also confirmed that I get the wrong plot.

using Plots

function make_plane(x, y, z)
    a = eltype(x)[]
    b = eltype(y)[]
    c = eltype(z)[]
    for i in x, j in y, k in z
        if i + j + k ≈ 1
            push!(a, i)
            push!(b, j)
            push!(c, k)
        end
    end
    return a,b,c
end

x = y = z = 0:0.1:1
surface(make_plane(x, y, z), camera = (60, 60), c = :blues)

The correct plot can be obtained as follows.

f(x, y) = x ≥ 0 && y ≥ 0 && x + y ≤ 1 ? 1 - x - y : NaN
x = y = 0:0.1:1
surface(x, y, f; camera = (60, 60), c = :blues)

I have used the trick that NaN is not plotted. (http://docs.juliaplots.org/latest/generated/gr/#gr-ref39)

I think it is an issue with the default gr() backend, since surface(make_plane(x, y, z)) plots fine under the pyplot() backend.

pyplot(fmt = :svg)
x = y = z = 0:0.1:1
surface(make_plane(x, y, z), camera = (70, 20), c = :blues)

2 Likes