# Plot with sticks or arrows

**URL:** https://discourse.julialang.org/t/plot-with-sticks-or-arrows/68422
**Category:** General Usage
**Tags:** plotting, plots, 3d
**Created:** [September 19, 2021, 7:50pm UTC](https://discourse.julialang.org/t/plot-with-sticks-or-arrows/68422 "2021-09-19T19:50:44Z")
**Posts on this page:** 1
**Showing post:** 14

<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: [September 21, 2021, 7:51am UTC](https://discourse.julialang.org/t/plot-with-sticks-or-arrows/68422/14 "2021-09-21T07:51:58Z")

</div>

It seems that the 3D quiver arrows in Plots.jl might be [work in progress](https://github.com/JuliaPlots/Plots.jl/pull/3134).

By extending this [user function](https://discourse.julialang.org/t/plots-jl-arrows-style-in-quiver/13659/6) to 3D, you can get:

##### Fixed 3d arrow head sizes:

 ![Plots_gr_fixed_3d_arrow_heads](https://global.discourse-cdn.com/julialang/original/3X/3/8/38081c753afd6610831ddfda98329e6a64c74db7.png)

##### Proportional 3d arrow head sizes:

 ![Plots_gr_proportional_3d_arrow_heads](https://global.discourse-cdn.com/julialang/original/3X/1/3/1359a54af1e14dac2c1927be451d632abbdd3b54.png)

> **Julia 1.7 Plots.jl code used**
>
> ```julia
> using LinearAlgebra, Plots; gr(dpi=600)
> 
> # as: arrow head size 0-1 (fraction of arrow length)
> # la: arrow alpha transparency 0-1
> function arrow3d!(x, y, z, u, v, w; as=0.1, lc=:black, la=1, lw=0.4, scale=:identity)
> (as < 0) && (nv0 = -maximum(norm.(eachrow([u v w]))))
> for (x,y,z, u,v,w) in zip(x,y,z, u,v,w)
> nv = sqrt(u^2 + v^2 + w^2)
> v1, v2 = -[u,v,w]/nv, nullspace(adjoint([u,v,w]))[:,1]
> v4 = (3*v1 + v2)/3.1623 # sqrt(10) to get unit vector
> v5 = v4 - 2*(v4'*v2)*v2
> (as < 0) && (nv = nv0) 
> v4, v5 = -as*nv*v4, -as*nv*v5
> plot!([x,x+u], [y,y+v], [z,z+w], lc=lc, la=la, lw=lw, scale=scale, label=false)
> plot!([x+u,x+u-v5[1]], [y+v,y+v-v5[2]], [z+w,z+w-v5[3]], lc=lc, la=la, lw=lw, label=false)
> plot!([x+u,x+u-v4[1]], [y+v,y+v-v4[2]], [z+w,z+w-v4[3]], lc=lc, la=la, lw=lw, label=false)
> end
> end
> 
> # input points and arrows
> x = y = 0:0.1:3π; z = zero(x)
> u = v = zero(x); w = sin.(x)
> 
> # arrows with fixed head sizes
> p = plot(camera=(20,30), legend=false)
> arrow3d!(x, zero(y), zero(z), u, w, v; as=-0.05, lc=:red, la=0.5)
> arrow3d!(x, zero(y), zero(z), u, v, w; as=-0.05, lc=:blue, la=0.5)
> display(p)
> 
> # arrows with proportional 5% head sizes
> p = plot(camera=(20,30))
> arrow3d!(x, zero(y), zero(z), u, w, v; as=0.05, lc=:red, la=0.5)
> arrow3d!(x, zero(y), zero(z), u, v, w; as=0.05, lc=:blue, la=0.5)
> display(p)
> 
> ```

---

_[View the full topic](https://discourse.julialang.org/t/plot-with-sticks-or-arrows/68422)._
