# Plots bug - arrows & xflip?

**URL:** https://discourse.julialang.org/t/plots-bug-arrows-xflip/137024
**Category:** Visualization
**Created:** [May 7, 2026, 3:58pm UTC](https://discourse.julialang.org/t/plots-bug-arrows-xflip/137024 "2026-05-07T15:58:41Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)
#### Post date: [May 7, 2026, 3:58pm UTC](https://discourse.julialang.org/t/plots-bug-arrows-xflip/137024/1 "2026-05-07T15:58:41Z")

</div>

Consider:

```julia
plot(sin; lw=2, xlim=[0,2pi],label="")
plot!([(1,-0.5),(pi,0)]; lw=2, lc=:red, arrow=arrow(:closed, :head, 2.0, 2.0), label="")

```

providing (as expected):

 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/c/3cfd5a30c2cba7c2a9ae57f5eeeb1191888c07fa.png)

But if I _flip_ the x axis, I get something “wrong”…

```julia
plot(sin; lw=2, xlim=[0,2pi],label="", xflip=true)
plot!([(1,-0.5),(pi,0)]; lw=2, lc=:red, arrow=arrow(:closed, :head, 2.0, 2.0), label="")

```

with result:

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

**Question** : Is this a bug, or am I doing something wrong??

---

<div class="post-metadata">

### Author: ![technocrat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/technocrat/32/220947_2.png) [@technocrat](https://discourse.julialang.org/u/technocrat)
#### Post date: [May 7, 2026, 4:41pm UTC](https://discourse.julialang.org/t/plots-bug-arrows-xflip/137024/2 "2026-05-07T16:41:57Z")

</div>

I’d classify that as at least an unhandled edge case. To work around in `Plots`

```julia-auto
using Plots
gr()

"""
    arrow_segment_annot!(p, x1, y1, x2, y2; color=:red, lw=2, arrowsize=10)

Draw a line from (x1,y1) to (x2,y2) and put an arrowhead at (x2,y2)
as a rotated Unicode arrow annotation. Works even with xflip=true.
"""
function arrow_segment_annot!(p, x1, y1, x2, y2; color=:red, lw=2, arrowsize=10)
    # Draw the line
    plot!(p, [x1, x2], [y1, y2]; lc=color, lw=lw, label=nothing)

    # Compute angle in degrees in data space
    θ = atan(y2 - y1, x2 - x1) * 180 / π

    # Add an arrowhead annotation at the end
    annotate!(p, x2, y2, text('➤', arrowsize, color, rotation=θ))

    return p
end

# Example with flipped x-axis
p = plot(sin, 0, 2π; lw=2, label="", xlim=(0, 2π), xflip=true)
arrow_segment_annot!(p, 1, -0.5, π, 0.0; color=:red, lw=2, arrowsize=12)
display(p)

```

 ![CleanShot 2026-05-07 at 09.38.30](https://global.discourse-cdn.com/julialang/original/3X/f/1/f1b20f51b7eda5e9b8a7621d4e259d5546137b33.png)

However, you can do this with less drama using `CairoMakie`

```julia-auto
using CairoMakie

f(x) = sin(x)

fig = Figure(resolution = (600, 400))
ax = Axis(fig[1, 1], xlabel = "x", ylabel = "y")

xs = range(0, 2π; length = 400)
lines!(ax, xs, f.(xs))

origin = Point2f(1, -0.5)
target = Point2f(π, 0.0)
direction = target - origin

arrows2d!(
    ax,
    [origin],
    [direction];
    color = :red,
    shaftwidth = 2,
    tipwidth = 10,
    tiplength = 15,
)

ax.xreversed = true

fig

```

 ![CleanShot 2026-05-07 at 09.44.18](https://global.discourse-cdn.com/julialang/original/3X/b/c/bccd6cc679297b20ff66c515d8d60cc79fe4257b.png)

---

<div class="post-metadata">

### Author: ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)
#### Post date: [May 7, 2026, 7:44pm UTC](https://discourse.julialang.org/t/plots-bug-arrows-xflip/137024/3 "2026-05-07T19:44:23Z")

</div>

I should probably look more into Makie… Problem is many of the packages I use, take advantage of recipes in Plots.
