# Plots.jl: arrows style in quiver()?

**URL:** https://discourse.julialang.org/t/plots-jl-arrows-style-in-quiver/13659
**Category:** Visualization
**Tags:** plotting
**Created:** [August 18, 2018, 10:57am UTC](https://discourse.julialang.org/t/plots-jl-arrows-style-in-quiver/13659 "2018-08-18T10:57:33Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![wrgr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wrgr/32/2796_2.png) [@wrgr](https://discourse.julialang.org/u/wrgr)
#### Post date: [August 18, 2018, 10:57am UTC](https://discourse.julialang.org/t/plots-jl-arrows-style-in-quiver/13659/1 "2018-08-18T10:57:33Z")

</div>

In Plots.jl,

```julia
quiver(x, y, gradient=(u, v), ...)

```

produces arrows with head sizes being independent of gradient magnitude, like this:  
 ![arrows](https://global.discourse-cdn.com/julialang/original/3X/5/f/5f9085f933f8649f4fb67e9b2aea471c697b270b.png)  
The vector in the bottom-left corner has a small norm, and its head looks disproportionally big. Does anybody know how to make arrow heads proportional to vector norms (smaller vector → smaller head), and overall how to style the arrows?  
A side question: documentation for Plots.jl is rather scarce, so I wonder whether there is some interface which allows to explore options available, without digging into the source?

---

<div class="post-metadata">

### Author: ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)
#### Post date: [August 18, 2018, 12:40pm UTC](https://discourse.julialang.org/t/plots-jl-arrows-style-in-quiver/13659/2 "2018-08-18T12:40:24Z")

</div>

For the real question - yes there is functionality for it, and I think it’s broken and there’s an issue for it.  
For the second question - yes, you can go to this table [Overview · Plots](https://docs.juliaplots.org/latest/attributes/) and look, but there’s also a programmatic interface to it:

```julia
julia> plotattr("arrow")
arrow {nothing (no arrows), Bool (if true, default arrows), Arrow object, or arg(s) that could be style or head length/widths}
arrows

Defines arrowheads that should be displayed at the end of path line segments (just before a NaN and the last non-NaN point). Used in quiverplot, streamplot, or similar.
Series attribute, default: nothing

```

---

<div class="post-metadata">

### Author: ![wrgr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wrgr/32/2796_2.png) [@wrgr](https://discourse.julialang.org/u/wrgr)
#### Post date: [August 18, 2018, 1:05pm UTC](https://discourse.julialang.org/t/plots-jl-arrows-style-in-quiver/13659/3 "2018-08-18T13:05:40Z")

</div>

@mkborregaard, thank you for the link, the description of `arrow` attribute says:  
“… or arg(s) that could be style or head length/widths”  
So is it possible to bind these lengths/widths to data, and how to do this? I’ve written

```julia
quiver(..., arrow=arrow(0.01, 0.01))

```

to no avail, just to test whether at least constant scaling works, but it doesn’t (indeed something is broken).  
I looked up the source, and `struct Arrow` contains `headlength` and `headwidth` as `Float64` fields, so I can’t really understand how to use these if I need to vary head size from vector to vector in the data.  
Are you aware of any other library which achieves this goal? I was thinking to go with old faithful Compose.jl, but it is not able to build on my system due to missing pangocairo or something like that.

---

<div class="post-metadata">

### Author: ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)
#### Post date: [August 18, 2018, 1:29pm UTC](https://discourse.julialang.org/t/plots-jl-arrows-style-in-quiver/13659/4 "2018-08-18T13:29:41Z")

</div>

TBH I think it’s something that Tom (who wrote Plots) stopped halfway through implementing and it’s just that nobody took it up. @dpsanders has requested this functionality several times. I guess it would be simple enough to do. This should just be a weakness of Plots, I’d bet that any of the well-featured plotting packages have this option.

---

<div class="post-metadata">

### Author: ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)
#### Post date: [March 16, 2021, 4:43am UTC](https://discourse.julialang.org/t/plots-jl-arrows-style-in-quiver/13659/5 "2021-03-16T04:43:13Z")

</div>

I hate to bump an old thread, but has there been any progress on this in the past couple years?

---

<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: [March 16, 2021, 10:02pm UTC](https://discourse.julialang.org/t/plots-jl-arrows-style-in-quiver/13659/6 "2021-03-16T22:02:07Z")

</div>

A simple user defined function `arrow0!` using Plots.jl, for displaying arrows with head sizes proportionally to their lengths (no bells and whistles):

```julia
using Plots; gr(legend=false)

# as: arrow head size 0-1 (fraction of arrow length)
# la: arrow alpha transparency 0-1
function arrow0!(x, y, u, v; as=0.07, lc=:black, la=1)
    nuv = sqrt(u^2 + v^2)
    v1, v2 = [u;v] / nuv, [-v;u] / nuv
    v4 = (3*v1 + v2)/3.1623 # sqrt(10) to get unit vector
    v5 = v4 - 2*(v4'*v2)*v2
    v4, v5 = as*nuv*v4, as*nuv*v5
    plot!([x,x+u], [y,y+v], lc=lc,la=la)
    plot!([x+u,x+u-v5[1]], [y+v,y+v-v5[2]], lc=lc, la=la)
    plot!([x+u,x+u-v4[1]], [y+v,y+v-v4[2]], lc=lc, la=la)
end

# Define some input points and arrows
N = 12;
x, y = 1 .+ 2* rand(N), 1 .+ 2*rand(N); # points
r, θ = rand(N), LinRange(0,2π,N)
u, v = r .* cos.(θ), r .* sin.(θ) # arrows 

# plot points and arrows with 10% head sizes
scatter(x, y, mc=:red, ms=2.5, ratio=1, ma=0.5)
for (x,y,u,v) in zip(x,y,u,v)
    display(arrow0!(x, y, u, v; as=0.1, lc=:blue, la=1))
end

```

![arrow_heads_with_variable_size](https://global.discourse-cdn.com/julialang/original/3X/f/7/f73fdd61869ab63a93fc4696388d12fc9c912f6b.png)

---

<div class="post-metadata">

### Author: ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)
#### Post date: [March 16, 2021, 11:37pm UTC](https://discourse.julialang.org/t/plots-jl-arrows-style-in-quiver/13659/7 "2021-03-16T23:37:19Z")

</div>

This is great, thank you. I ended up making something pretty similar where I defined a custom marker using `Shape()` and used rotation matrices inside a call to `scatter!()`.

---

<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: [March 17, 2021, 7:08am UTC](https://discourse.julialang.org/t/plots-jl-arrows-style-in-quiver/13659/8 "2021-03-17T07:08:08Z")

</div>

@maxkapur, the rotation matrices were avoided by adding known unit orthogonal vectors to make the arrow heads turn.  
_PS: this was further simplified in the revised version above_
