# 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:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccmejia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccmejia/32/18680_2.png) [@ccmejia](https://discourse.julialang.org/u/ccmejia)\
**Post date:** [September 19, 2021, 7:50pm UTC](https://discourse.julialang.org/t/plot-with-sticks-or-arrows/68422/1 "2021-09-19T19:50:44Z")

</div>

Hi there,  
I’m trying to plot scatter data with impulses, specifically with arrows. But, it seems that it does not exist in seriestype options. Any idea about how I can obtain that?  
Thanks in advance!

---

<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:** [September 20, 2021, 4:49am UTC](https://discourse.julialang.org/t/plot-with-sticks-or-arrows/68422/2 "2021-09-20T04:49:29Z")

</div>

Which plotting package are you using?

---

<div class="post-metadata">

**Author:** ![ccmejia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccmejia/32/18680_2.png) [@ccmejia](https://discourse.julialang.org/u/ccmejia)\
**Post date:** [September 20, 2021, 12:42pm UTC](https://discourse.julialang.org/t/plot-with-sticks-or-arrows/68422/3 "2021-09-20T12:42:10Z")

</div>

Hi! I am using Plots.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 20, 2021, 12:46pm UTC](https://discourse.julialang.org/t/plot-with-sticks-or-arrows/68422/4 "2021-09-20T12:46:43Z")

</div>

Using PyPlot you can use the `arrow` annotation function ([python - Arrows on Scatter - Stack Overflow](https://stackoverflow.com/questions/37711936/arrows-on-scatter)), though you have to write a manual loop to add an arrow for each point.

---

<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:** [September 20, 2021, 1:29pm UTC](https://discourse.julialang.org/t/plot-with-sticks-or-arrows/68422/5 "2021-09-20T13:29:07Z")

</div>

Something like this here?

> **[Quiver plots](https://goropikari.github.io/PlotsGallery.jl/src/quiver.html)**
>
> \[“These figures are made by Plots.jl”\]

---

<div class="post-metadata">

**Author:** ![ccmejia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccmejia/32/18680_2.png) [@ccmejia](https://discourse.julialang.org/u/ccmejia)\
**Post date:** [September 20, 2021, 6:35pm UTC](https://discourse.julialang.org/t/plot-with-sticks-or-arrows/68422/6 "2021-09-20T18:35:58Z")

</div>

Hi there, thank you both for suggestions. The plot is really easy with gnuplot:

`pl sin(x) w impulses, sin(x) w p pt 8 ps 4, sin(x) w l`

 ![arrows](https://global.discourse-cdn.com/julialang/original/3X/4/b/4b8f95545d618be57953e49732b23bbbbab4867b.png)

But, with Julia it seems (for me) that is not so easy.

---

<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 20, 2021, 7:23pm UTC](https://discourse.julialang.org/t/plot-with-sticks-or-arrows/68422/7 "2021-09-20T19:23:24Z")

</div>

Try this:

```julia
using Plots; gr()
plot(0:0.1:2π, sin, shape=:utriangle, st=:sticks)

```

![plot_gr_stick](https://global.discourse-cdn.com/julialang/original/3X/f/2/f2af8ff79cd08b3bff7b0fd6cffe01b584d12526.png)

---

<div class="post-metadata">

**Author:** ![ccmejia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccmejia/32/18680_2.png) [@ccmejia](https://discourse.julialang.org/u/ccmejia)\
**Post date:** [September 20, 2021, 7:26pm UTC](https://discourse.julialang.org/t/plot-with-sticks-or-arrows/68422/8 "2021-09-20T19:26:56Z")

</div>

> [@rafael.guerra](#):
>
> ```julia
> using Plots; gr()
> plot(0:0.1:2π, sin, markershape=:utriangle, st=:sticks)
> 
> ```

Great! Thank you so much!

---

<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 20, 2021, 7:27pm UTC](https://discourse.julialang.org/t/plot-with-sticks-or-arrows/68422/9 "2021-09-20T19:27:48Z")

</div>

Suggest modifying the title of your post to “Plot with sticks” 🙂

---

<div class="post-metadata">

**Author:** ![ccmejia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccmejia/32/18680_2.png) [@ccmejia](https://discourse.julialang.org/u/ccmejia)\
**Post date:** [September 20, 2021, 7:32pm UTC](https://discourse.julialang.org/t/plot-with-sticks-or-arrows/68422/10 "2021-09-20T19:32:10Z")

</div>

Done.

---

<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 20, 2021, 7:40pm UTC](https://discourse.julialang.org/t/plot-with-sticks-or-arrows/68422/11 "2021-09-20T19:40:47Z")

</div>

You can check if you like the display better using `quiver` arrows, as suggested above:

```julia
x = 0:0.1:2π
y = sin.(x)
quiver(x, zero(y), quiver=(zero(x), y))

```

![plot_gr_quiver_sticks](https://global.discourse-cdn.com/julialang/original/3X/f/6/f6c295670adb67d37b6326c1476f02eeded19c6e.png)

In which case, you could rename post title: “Plot with sticks or arrows” 😉

---

<div class="post-metadata">

**Author:** ![ccmejia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccmejia/32/18680_2.png) [@ccmejia](https://discourse.julialang.org/u/ccmejia)\
**Post date:** [September 20, 2021, 7:48pm UTC](https://discourse.julialang.org/t/plot-with-sticks-or-arrows/68422/12 "2021-09-20T19:48:18Z")

</div>

No doubt. It looks more appropriate to my concerns.  
Thank you again!

---

<div class="post-metadata">

**Author:** ![ccmejia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccmejia/32/18680_2.png) [@ccmejia](https://discourse.julialang.org/u/ccmejia)\
**Post date:** [September 20, 2021, 9:16pm UTC](https://discourse.julialang.org/t/plot-with-sticks-or-arrows/68422/13 "2021-09-20T21:16:41Z")

</div>

My next step was move to 3d, but now I lose the head of arrows…

```julia
	x1 = 0:0.1:3π
	y1 = x1
	z1 = sin.(x1)
	quiver(x1, zero(y1), zero(y1), quiver=(zero(x1), z1, zero(y1)))	
	quiver!(x1, zero(x1), zero(x1), quiver=(zero(x1), zero(x1), z1))

```

![Screen Shot 2021-09-20 at 4.15.59 PM](https://global.discourse-cdn.com/julialang/original/3X/3/7/371a0114d6d865ce57a902579b253dc305a100e7.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:** [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)
> 
> ```

---

<div class="post-metadata">

**Author:** ![ccmejia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccmejia/32/18680_2.png) [@ccmejia](https://discourse.julialang.org/u/ccmejia)\
**Post date:** [September 22, 2021, 12:33am UTC](https://discourse.julialang.org/t/plot-with-sticks-or-arrows/68422/15 "2021-09-22T00:33:15Z")

</div>

I will take a look.  
Thank you!
