Wrong image when trying to create a simple 3d surface

Hi. I’m Trying to plot a 3D triangle plane using Plots.jl and surface. But an odd extra surface is showing up. Can someone tell-me what i’m doing wrong? Code below with some experiments.
Thanks in advance!!!

using Plots
Plots.PyPlotBackend()

#1st try
struct Point
    x::Number
    y::Number
	z::Number
end
function triangle(p1::Point, p2::Point, p3::Point)
	x = [p1.x, p2.x, p3.x, p1.x]
	y = [p1.y, p2.y, p3.y, p1.y]
	z = [p1.z, p2.z, p3.z, p1.z]
	return (x,y,z)
end
A = Point(1,0,0); 
B = Point(0,1,0); 
C = Point(0,0,1);
tri = triangle(A,B,C)

plot(tri, leg=false, camera = (75,45))  #Fill options doesn't work here in 1st plot???
scatter!(tri, leg=false)

#2nd Try
x = collect(0:0.1:1);
y = collect(0:0.1:1);
z = collect(0:0.1:1);
function make_plane(x,y,z)
	a = []
	b = []
	c = []
	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

plane = make_plane(x,y,z)

plot(plane, camera = (60,60)) #I know this is wrong, but adding this 2nd for reference!

surface(plane, camera = (60,60), c = :blues) #this plot 3rd has wrong behavior

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