Plots.jl: arrows style in quiver()?

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

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

8 Likes