Arrows not working on log-log plot (GR)

,

If I run code like this, the plot doesn’t work correctly when I use the arrows. Any suggestions to fix this?

using Plots
gr()

plot( [0.1, 10], [0.1, 10],
    xscale=:log10,
    yscale=:log10,
    xlims=(0.01, 100),
    ylims=(0.01, 100),
    arrow=(:closed, :both, 5,5)
)

image

It looks like an ugly bug.

Herein a workaround for loglog plots with aspect ratio = 1.

NB: edited code as there seems to be another bug, with aspect_ratio not being respected in loglog plots if range of xlims != ylims

using Plots; gr(legend=false)

# Define some input data:
x, y = 0.1, 0.1         # vector origin
u, v = 9.9, 99.9        # vector
xl, yl = (0.01, 100), (0.01, 200)  # loglog plot limits (have to be modified to max range)

# plot arrowheads as rotated unicode characters (OK for ratio=1):
lminmax = (minimum([xl[1];yl[1]]), maximum([xl[2];yl[2]]))
r = atan(log10.(1+v/y), log10.(1+u/x)) * 180/pi    # rotation angle
p = plot([x,x+u], [y,y+v], lc=:blue, xlabel="X",ylabel="Y")
plot!(ratio=1, scale=:log10, xlims=lminmax, ylims=lminmax)
annotate!(x+u,y+v, text('\u27A4', 9, :blue, rotation=r))
annotate!(x,y, text('\u27A4', 9, :blue, rotation=r+180))

Plots_arrowheads_in_loglog_scale

NB: it should be possible to correct the rotation angles for the general case where ratio != 1

Thanks for taking the time to supply a workaround. Should I file a bug report with Plots or GR?

By all means, please go ahead (Plots.jl).

For whatever it is worth, and to complement workaround above for ratio=1, the following seems to work for “arbitrary” aspect ratios:

using Plots; gr(legend=false)

# Define some input data:
x, y = 0.1, 100         # vector origin
u, v = 9.9, -99.99      # vector
xl, yl = (0.01, 200), (0.001, 50)  # loglog plot limits (have to be modified to max range)

# plot arrowheads as rotated unicode characters:
lminmax = (minimum([xl[1];yl[1]]), maximum([xl[2];yl[2]]))
p = plot([x,x+u], [y,y+v], lc=:red,xlims=lminmax,ylims=lminmax,scale=:log10, xlabel="X",ylabel="Y")
lxl, lyl = log10.(Plots.xlims(p)),  log10.(Plots.ylims(p))
sz =  p.attr[:size]
ar = (lxl[2]-lxl[1])/(lyl[2]-lyl[1])*sz[2]/sz[1]
r = atan(ar*log10.(1+v/y), log10.(1+u/x)) * 180/pi    # rotation angle
annotate!(x+u,y+v, text('\u27A4', 9, :red, rotation=r))
annotate!(x,y, text('\u27A4', 9, :red, rotation=r+180))

Plots_arrowheads_in_loglog_scale_any_aspect_ratio