# Can Gnuplot Made by Lazarus Plot 3D surface along with its orthogonal line in Julia?

**URL:** <https://discourse.julialang.org/t/can-gnuplot-made-by-lazarus-plot-3d-surface-along-with-its-orthogonal-line-in-julia/91429>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [December 8, 2022, 2:50pm UTC](https://discourse.julialang.org/t/can-gnuplot-made-by-lazarus-plot-3d-surface-along-with-its-orthogonal-line-in-julia/91429 "2022-12-08T14:50:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [December 8, 2022, 2:50pm UTC](https://discourse.julialang.org/t/can-gnuplot-made-by-lazarus-plot-3d-surface-along-with-its-orthogonal-line-in-julia/91429/1 "2022-12-08T14:50:46Z")

</div>

I have been looking how to create this:

![Capture d’écran_2022-08-19_19-27-15](https://global.discourse-cdn.com/julialang/original/3X/a/d/adcd80dd9d49b8bc327bfcc157430b161158fd55.png)

Then saw this link:

> **[Gnuplot examples](https://lazarusa.github.io/gnuplot-examples/dev/)**
>
> Gnuplot Examples

and this discussion:

> [@Fill a curve in 3D](https://discourse.julialang.org/t/fill-a-curve-in-3d/37890/3):
>
> Don’t know if it applies, but in [Gnuplot.jl](https://github.com/gcalderone/Gnuplot.jl) is quite easy: x = 0.:0.05:3; y = 0.:0.05:3; z = @. sin(x) \* exp(-(x+y)) using Gnuplot @gsp xlab="X" ylab="Y" linetypes(:Set1\_5, lw=3) :- @gsp :- "set style fill transparent solid 0.3" :- @gsp :- "set xyplane at 0" "set grid" :- @gsp :- x y z z.\*0 z "w zerror t 'Data'" :- @gsp :- x.\*0 y z "w l notit" :- # projection on x=0 @gsp :- x y.\*0 z "w l notit" # projection on y=0 save(term="pngcairo", output="output.png") [output]

I tried with LazySets to create without the plane:

```julia
using LazySets, LaTeXStrings
using Plots: plot, plot!, text, lens!, bbox
gr()
p(args...; kwargs...) = plot(xlims=(0,4), ylims=(0,4), ratio=1, lab="",
                        xlab=L"x_{1}", ylab=L"x_{2}", args...; kwargs...)
p!(args...; kwargs...) = plot!(lab="", args...; kwargs...);

p(xlims=(0,2), ylims=(0,2))
a = [1.0, 1.0]
b = 2.0

H = Hyperplane(a, b)

p!(H, linewidth=2)

# normal arrow
p!([1.0, 1.5], [1.0, 1.5], linecolor=:red, arrow=:arrow,
    linestyle=:dash, width=2, annotations=(1.15, 1.3, text(L"\textbf{n}", 10)))
p!([1.0, 0.5], [1.0, 1.5], linecolor=:red, arrow=:arrow,
    linestyle=:dash, width=2, annotations=(0.75, 1.5, text(L"P(x,y)", 10)))

annotate!([(1.5, 1.6, text(L"(a,b)", 10)), 
           (0.75, 1.0, text(L"P_{0}(x_{0},y_{0})", 10))])

scatter!([1], [1], color = "red", label="", markersize = 4)
scatter!([1.5], [1.5], color = "red", label="", markersize = 4)
scatter!([0.5], [1.5], color = "red", label="", markersize = 4)

```

![Capture d’écran_2022-12-08_21-49-46](https://global.discourse-cdn.com/julialang/original/3X/a/d/add2c96a3777c12b39459cbad0f7d8ea9a2ef824.png)

Hopefully anyone can help me…

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [December 8, 2022, 6:17pm UTC](https://discourse.julialang.org/t/can-gnuplot-made-by-lazarus-plot-3d-surface-along-with-its-orthogonal-line-in-julia/91429/2 "2022-12-08T18:17:33Z")

</div>

I always wanna to do a simplex, quantum mechanics memories. Anyway, not a solution with Gnuplot, but I hope something with Makie.jl also works for you. The code is [here](https://beautiful.makie.org/dev/examples/generated/2d/meshes/simplex/) and below:

> **Code**
>
> ```plaintext
> using GLMakie
> GLMakie.activate!()
> vertices = [
> 0 0 0
> 1 0 0
> 0 1 0 
> 0 0 1
> ]
> faces = [
> 3 2 1
> 4 1 2
> 4 3 1
> 4 2 3
> ]
> ## m = GLMakie.GeometryBasics.Mesh(GLMakie.Makie.to_vertices(vertices), GLMakie.Makie.to_triangles(faces))
> ## mesh(m)
> 
> marker = Sphere(Point3f(0), 1) # 0 -> -0.5, fully inside, 0 -> 0.5 fully outside
> 
> fig = Figure(resolution = (600,600))
> ax = LScene(fig[1,1], show_axis=false)
> m = mesh!(ax, vertices, faces; color = :white, transparency=true,)
> poly!(ax, vertices, faces; color = :transparent, 
> transparency=true, strokewidth = 1.0)
> meshscatter!(ax, 
> Point3f(1/3, 1/3,1/3), # you need to calculate this for your use case
> marker = marker, markersize = 0.025, transparency=true)
> ## the following are not over the plane nither perpendicular.
> arrows!(ax, 
> [Point3f(1/3, 1/3,1/3)], # you need to calculate this for your use case
> [Point3f(0.2, 0.1,0.3)], # you need to calculate this for your use case
> arrowsize = Vec3f(0.05, 0.05, 0.08),
> color = :red,
> arrowcolor = :black)
> arrows!(ax, 
> [Point3f(1/3, 1/3,1/3)], # you need to calculate this for your use case
> [Point3f(-0.1, -0.1,0.3)], # you need to calculate this for your use case
> arrowsize = Vec3f(0.08, 0.08, 0.08),
> linewidth = 0.02,
> color = :dodgerblue,
> arrowcolor = :orange)
> zoom!(ax.scene, cameracontrols(ax.scene), 0.9)
> rotate!(ax.scene, -0.1)
> fig
> 
> ```

 ![Screenshot 2022-12-08 at 19.10.16](https://global.discourse-cdn.com/julialang/original/3X/b/8/b8ed38b57b56eb035d73d29fa09e08083f585de7.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:** [December 8, 2022, 9:12pm UTC](https://discourse.julialang.org/t/can-gnuplot-made-by-lazarus-plot-3d-surface-along-with-its-orthogonal-line-in-julia/91429/3 "2022-12-08T21:12:09Z")

</div>

With Plots.jl it is possible to draw such a transparent plane and the orthogonal arrows:

 ![Plots_plane3d_normal_arrows](https://global.discourse-cdn.com/julialang/original/3X/a/7/a77da817ad2dbb5cbc1beeece7412f1d6a5017a9.png)

However, there is no 3D annotation, only 2D, with which the text could be placed in the right places [after some trial and error](https://discourse.julialang.org/t/how-to-add-latex-annotations-for-3-d-plots-backend-gr-and-pyplot/85473/4).

> **Plots.jl code**
>
> ```julia
> using Plots; pyplot(dpi=100)
> 
> function arrow3d!(P, V; lc=:black, lw=2, camera=(10,30))
> n = 7 # break arrowhead in n-parts
> ni = (0:n-1)/n 
> lwi = range(0.1, 4*lw, n) # arrowhead variable thickness                   
> d = V .* 1/10 # controls relative arrow length
> P1 = P + V
> P0 = P1 - d
> plot!([P[1], P1[1]], [P[2], P1[2]], [P[3], P1[3]], lw=lw, lc=lc, label=false, camera=camera)
> for (i,li) in zip(ni,lwi)
> di = d .* i
> plot!([P0[1], P1[1]-di[1]], [P0[2], P1[2]-di[2]], [P0[3], P1[3]-di[3]], lw=li, lc=lc, label=false)
> end
> return Plots.current()
> end
> 
> using LinearAlgebra
> p1, p2, p3 = [2,0,0], [0,2,0], [0,0,2]
> c = .+(p1, p2, p3) ./ 3
> n = cross(p1-p2, p1-p3) ./ (norm(p1-p2)*norm(p1-p3))
> surface(p1, p2, p3, c=:blues, alpha=0.3, aspect_ratio=:equal, cbar=false)
> scatter!([c[1]], [c[2]], [c[3]], ms=7, label=false)
> arrow3d!(c, n; lc=:blue, camera=(70,30))
> arrow3d!(c, (p3-c)*1/3; lc=:blue, camera=(70,30))
> 
> ```

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [December 15, 2022, 6:36am UTC](https://discourse.julialang.org/t/can-gnuplot-made-by-lazarus-plot-3d-surface-along-with-its-orthogonal-line-in-julia/91429/4 "2022-12-15T06:36:51Z")

</div>

Don’t worry I am still at chapter 4 calculus, one day I will ask in this discourse how to create great simplex calculation.

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [December 15, 2022, 7:06am UTC](https://discourse.julialang.org/t/can-gnuplot-made-by-lazarus-plot-3d-surface-along-with-its-orthogonal-line-in-julia/91429/5 "2022-12-15T07:06:30Z")

</div>

I like Plots.jl !

Thanks for the code, I will work with the annotations or edit it with inkscape is easier.
