# Plotting a Plane from a function using Makie

**URL:** <https://discourse.julialang.org/t/plotting-a-plane-from-a-function-using-makie/44675>\
**Category:** Visualization\
**Created:** [August 10, 2020, 12:13pm UTC](https://discourse.julialang.org/t/plotting-a-plane-from-a-function-using-makie/44675 "2020-08-10T12:13:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fermion4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fermion4/32/17160_2.png) [@fermion4](https://discourse.julialang.org/u/fermion4)\
**Post date:** [August 10, 2020, 12:13pm UTC](https://discourse.julialang.org/t/plotting-a-plane-from-a-function-using-makie/44675/1 "2020-08-10T12:13:53Z")

</div>

I just started using Makie to plot. Is it possible to plot a plane directly from a given function?  
Eg. I have the following function:  
`y1(y2,y3) = -y2 -y3 - 1.0`  
I would like to give intervals for y2 and y3 and directly get a plot of y1.  
I have already done this in Mathematica.  
I know that it is possible to give single points and make a plane like in:  
[https://discourse.julialang.org/t/plotting-a-transparent-planes-boxes-with-makie/21875](https://discourse.julialang.org/t/plotting-a-transparent-planes-boxes-with-makie/21875)

but it’s not convenient for me because I would have to define the points by hand each time.

---

<div class="post-metadata">

**Author:** ![cserteGT3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/csertegt3/32/8283_2.png) [@cserteGT3](https://discourse.julialang.org/u/cserteGT3)\
**Post date:** [August 10, 2020, 2:59pm UTC](https://discourse.julialang.org/t/plotting-a-plane-from-a-function-using-makie/44675/2 "2020-08-10T14:59:03Z")

</div>

I’m not sure I understand your question correctly, but if you have multiple functions and you want to do the same things with those, you can pass them as a function argument and call them inside a function.  
A (not working) example would be something like:

```julia
using Makie
y1(x2, x3) = -x2-x3-1.0

function plotfunction(y_2, y_3, f)
  # call f with the given arguments
  y_1 = f(y_2, y_3)
  # transform/compute the points as you wish
  mesh([y_1, y_2, y_3])
end

y2 = ...
y3 = ...
plotfunction(y2, y3, y1)

# define another function
y4(x2,x3) = -x2-x3-5.0
plotfunction(y2, y3, y4)

```

I hope that this helps, if not, and you could provide an example how you “define the points by hand each time”, I could alter this example as well.

---

<div class="post-metadata">

**Author:** ![fermion4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fermion4/32/17160_2.png) [@fermion4](https://discourse.julialang.org/u/fermion4)\
**Post date:** [August 10, 2020, 3:33pm UTC](https://discourse.julialang.org/t/plotting-a-plane-from-a-function-using-makie/44675/3 "2020-08-10T15:33:04Z")

</div>

Thanks for your answer! I think my first post was a bit unclear sorry abou that. I am trying to port what I did in mathemartica to julia. This is what I do in mathematica

```julia
y1[y2_, y3_] = 1 - y2 - y3; 
Plot3D[y1[y2, y3], {y2, -10, 10}, {y3, -10, 10}, 
 PlotStyle -> Opacity[0.3], PlotLabels -> "Manifold"]

```

The output looks like this (ignore the points):

![test](https://global.discourse-cdn.com/julialang/original/3X/a/9/a9ce80eece294513be98981489f6c37a5f34c88e.png)

The original is also interactive like in Makie plots!  
The example I have shown here is very simple but later on i want to plot more complex manifolds.  
It would be nice to have something like this where i only have to define the ranges for eg. y2 and y3.  
Any ideas how I could implement this?

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [August 10, 2020, 4:22pm UTC](https://discourse.julialang.org/t/plotting-a-plane-from-a-function-using-makie/44675/4 "2020-08-10T16:22:31Z")

</div>

If you have two ranges, say `x = 0:0.1:1` and `y = 0:0.1:1`, you can just do `surface(x, y, f)`. Automatically selecting points in a smart way is in general not completely trivial, and I think there is only a 1D implementation in Julia [here](https://github.com/JuliaPlots/PlotUtils.jl/blob/master/src/adapted_grid.jl).

If you have ideas on how to do the 2D version, it would be a good PR to PlotUtils. Does Mathematica use an adaptive grid for 2D, or do they just take uniformly spaced points on x and y axis?

---

<div class="post-metadata">

**Author:** ![fermion4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fermion4/32/17160_2.png) [@fermion4](https://discourse.julialang.org/u/fermion4)\
**Post date:** [August 14, 2020, 9:32am UTC](https://discourse.julialang.org/t/plotting-a-plane-from-a-function-using-makie/44675/5 "2020-08-14T09:32:19Z")

</div>

I am not sure what mathematica does since they are not open source. But i am pretty sure that they do not just use uniformly spaced points. Even very complex surfaces are always plotted very smoothly.

And you suggestion solved my problem. Thanks piever!
