# Wrong image when trying to create a simple 3d surface

**URL:** <https://discourse.julialang.org/t/wrong-image-when-trying-to-create-a-simple-3d-surface/64767>\
**Category:** New to Julia\
**Created:** [July 16, 2021, 7:02pm UTC](https://discourse.julialang.org/t/wrong-image-when-trying-to-create-a-simple-3d-surface/64767 "2021-07-16T19:02:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rodolforbcoutinho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rodolforbcoutinho/32/27067_2.png) [@rodolforbcoutinho](https://discourse.julialang.org/u/rodolforbcoutinho)\
**Post date:** [July 16, 2021, 7:02pm UTC](https://discourse.julialang.org/t/wrong-image-when-trying-to-create-a-simple-3d-surface/64767/1 "2021-07-16T19:02:37Z")

</div>

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!!!

```julia
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

```

 ![Triangles_V1](https://global.discourse-cdn.com/julialang/original/3X/4/a/4a343c90ccc199c59ccd6deaf7048e90b9795719.png)

---

<div class="post-metadata">

**Author:** ![genkuroki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/genkuroki/32/18030_2.png) [@genkuroki](https://discourse.julialang.org/u/genkuroki)\
**Post date:** [July 16, 2021, 8:19pm UTC](https://discourse.julialang.org/t/wrong-image-when-trying-to-create-a-simple-3d-surface/64767/2 "2021-07-16T20:19:52Z")

</div>

I also confirmed that I get the wrong plot.

```julia
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)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/d/dd23585cb90be42812c267a29b8a19f8ca7f15ee.jpeg)

The correct plot can be obtained as follows.

```julia
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)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/3/93f1cbafa27c6b6a16a5ac6a06a68f49a22e8d0b.jpeg)

I have used the trick that NaN is not plotted. ([http://docs.juliaplots.org/latest/generated/gr/#gr-ref39](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.

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

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/a/9a35f78943a366c1893bab7440230e3d49699361.jpeg)
