# Arrows not working on log-log plot (GR)

**URL:** https://discourse.julialang.org/t/arrows-not-working-on-log-log-plot-gr/61454
**Category:** Visualization
**Tags:** bug, gr
**Created:** [May 19, 2021, 3:27pm UTC](https://discourse.julialang.org/t/arrows-not-working-on-log-log-plot-gr/61454 "2021-05-19T15:27:42Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![white-c](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/white-c/32/16410_2.png) [@white-c](https://discourse.julialang.org/u/white-c)
#### Post date: [May 19, 2021, 3:27pm UTC](https://discourse.julialang.org/t/arrows-not-working-on-log-log-plot-gr/61454/1 "2021-05-19T15:27:43Z")

</div>

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

```julia
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](https://global.discourse-cdn.com/julialang/original/3X/9/2/928a591df3601df403122645777e7fcfcb0f006f.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: [May 20, 2021, 10:59pm UTC](https://discourse.julialang.org/t/arrows-not-working-on-log-log-plot-gr/61454/2 "2021-05-20T22:59:22Z")

</div>

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_

```julia
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](https://global.discourse-cdn.com/julialang/original/3X/a/3/a3a1b5296a9a2d347b30517e4e3e0ff949805b70.png)

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

---

<div class="post-metadata">

### Author: ![white-c](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/white-c/32/16410_2.png) [@white-c](https://discourse.julialang.org/u/white-c)
#### Post date: [May 21, 2021, 12:46pm UTC](https://discourse.julialang.org/t/arrows-not-working-on-log-log-plot-gr/61454/3 "2021-05-21T12:46:12Z")

</div>

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

---

<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: [May 21, 2021, 1:00pm UTC](https://discourse.julialang.org/t/arrows-not-working-on-log-log-plot-gr/61454/4 "2021-05-21T13:00:12Z")

</div>

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

---

<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: [May 22, 2021, 7:27pm UTC](https://discourse.julialang.org/t/arrows-not-working-on-log-log-plot-gr/61454/5 "2021-05-22T19:27:15Z")

</div>

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

```julia
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](https://global.discourse-cdn.com/julialang/original/3X/b/6/b6fa003d064bfcc0e94d2959423f9d3dbc82d69a.png)

---

<div class="post-metadata">

### Author: ![Elyco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elyco/32/18418_2.png) [@Elyco](https://discourse.julialang.org/u/Elyco)
#### Post date: [October 26, 2022, 6:10am UTC](https://discourse.julialang.org/t/arrows-not-working-on-log-log-plot-gr/61454/6 "2022-10-26T06:10:04Z")

</div>

Hi,  
Is there any update for this issue?  
It’s seem something that should be included inside Plots.jl.
