# Surface plot

**URL:** <https://discourse.julialang.org/t/surface-plot/82544>\
**Category:** General Usage\
**Tags:** plot, implicit-equation\
**Created:** [June 10, 2022, 5:53am UTC](https://discourse.julialang.org/t/surface-plot/82544 "2022-06-10T05:53:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDA](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@SDA](https://discourse.julialang.org/u/SDA)\
**Post date:** [June 10, 2022, 5:53am UTC](https://discourse.julialang.org/t/surface-plot/82544/1 "2022-06-10T05:53:17Z")

</div>

There is no doubt a very simple answer to this that I’ve overlooked. How would one plot a surface x=y, where z is any real number?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 10, 2022, 7:36am UTC](https://discourse.julialang.org/t/surface-plot/82544/2 "2022-06-10T07:36:02Z")

</div>

Which plotting library are you asking about? Have you tried googling or searching the forum? For me the first google hit is:

> [@Plotting a 3D Surface](https://discourse.julialang.org/t/plotting-a-3d-surface/17143):
>
> How would I plot the surface f(x,y)=xy-y-x+1 between \sqrt2\leq y\leq2 using PyPlot; x = collect(Float16, range(-2,length=100,stop=2)); y = collect(Float16, range(sqrt(2),length=100, stop=2)); z = (x.\*y).-y.-x.+1; surf(x,y,z); [Figure\_1-1]

and the second is:

> <https://stackoverflow.com/questions/66417677/3d-surface-plot-in-julia>

---

<div class="post-metadata">

**Author:** ![SDA](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@SDA](https://discourse.julialang.org/u/SDA)\
**Post date:** [June 10, 2022, 7:45am UTC](https://discourse.julialang.org/t/surface-plot/82544/3 "2022-06-10T07:45:54Z")

</div>

Yes, thank you I’ve seen that. It explains what to do when z=something. I am asking for the specific case where the plane is defined with two variables x=y.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 10, 2022, 8:31am UTC](https://discourse.julialang.org/t/surface-plot/82544/4 "2022-06-10T08:31:46Z")

</div>

Sorry it seems I don’t really understand what you’re asking. The last example of the SO answer is:

```julia
julia> x = y = 0:0.1:10
0.0:0.1:10.0

julia> z = f.(x', y) ; # note the ' which permutes the dims of x

julia> surface(x, y, z)

```

so here indeed `x=y`. Could you maybe elaborate a little on what it is you’re trying to do and what’s going wrong?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 10, 2022, 9:02am UTC](https://discourse.julialang.org/t/surface-plot/82544/5 "2022-06-10T09:02:07Z")

</div>

In 3D space, x=y is a vertical plane. Using Plots.jl’s plotlyjs backend, one way to plot vertical surfaces [is shown in this other post](https://discourse.julialang.org/t/2d-plot-in-3d-scene/80708/4). I think you just need to apply a trivial 45 degrees rotation to the vertical plane meshes shown, in order to obtain the x=y surface.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 10, 2022, 9:06am UTC](https://discourse.julialang.org/t/surface-plot/82544/6 "2022-06-10T09:06:38Z")

</div>

There is an [implicit 3D plotting package](https://www.juliapackages.com/p/implicit3dplotting) that provides a more elegant solution.

---

<div class="post-metadata">

**Author:** ![SDA](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@SDA](https://discourse.julialang.org/u/SDA)\
**Post date:** [June 14, 2022, 12:29am UTC](https://discourse.julialang.org/t/surface-plot/82544/7 "2022-06-14T00:29:19Z")

</div>

In my example z cannot be defined as a function but rather is simply any real value and the plane is entirely defined by x=y. In this case what should replace the f.(x’,y)? Thank you for trying to help me.

---

<div class="post-metadata">

**Author:** ![SDA](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@SDA](https://discourse.julialang.org/u/SDA)\
**Post date:** [June 14, 2022, 1:09am UTC](https://discourse.julialang.org/t/surface-plot/82544/8 "2022-06-14T01:09:21Z")

</div>

Thank you for pointing me to this package. It looks like it might be a good solution:

> using Implicit3DPlotting  
> f(x) = x[1]-x[2]  
> plot\_implicit\_surface(f; transparency=true)

 ![Screen Shot 2022-06-14 at 9.07.27 am](https://global.discourse-cdn.com/julialang/original/3X/7/6/766f91fe0be583fd4e6a168d0b4348ae4b4c64bc.png)

Improving the way the plot looks is tricky and was hoping for something that could be overlaid onto existing plots.

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [June 14, 2022, 8:25pm UTC](https://discourse.julialang.org/t/surface-plot/82544/9 "2022-06-14T20:25:31Z")

</div>

Each plane can be plotted as a parameterized surface.  
In particular, x=y, can be parameterized as:

```julia
x=u
y=u,
z=v

```

where u and v belong to some intervals.  
Example:

```julia
using PlotlyJS
ul= range(-1, 1, length=10)
vl= range(0, 0.75, length=8)
u= [s for t in vl, s in ul]
v= [t for t in vl, s in ul]
pl= Plot(surface(x=u, y=u, z=v, colorscale=[[0, "#ADD8E6"], [1, "#ADD8E6"]], 
         showscale=false),
         Layout(width=500, height=400, scene_camera_eye=attr(x=1.95, y=1, z=0.75)))

```

![planexeqy](https://global.discourse-cdn.com/julialang/original/3X/6/5/659eb62ab42815e23dd789b7a8ca9c23aff57511.png)

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 14, 2022, 10:49pm UTC](https://discourse.julialang.org/t/surface-plot/82544/10 "2022-06-14T22:49:48Z")

</div>

> [@SDA](#):
>
> Improving the way the plot looks is tricky and was hoping for something that could be overlaid onto existing plots.

The implicit 3D plotting package uses Makie.jl and you can ask questions in this forum and the experts will guide you. If the existing plots are also in Makie, I guess the overlaying should be possible.

---

<div class="post-metadata">

**Author:** ![SDA](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@SDA](https://discourse.julialang.org/u/SDA)\
**Post date:** [June 15, 2022, 12:59am UTC](https://discourse.julialang.org/t/surface-plot/82544/11 "2022-06-15T00:59:49Z")

</div>

Thank you, this is perfect for what I was looking for.
