Arrows in plots

I want to plot lines with arrows at the end of the lines. Following this thread, I got:
obtained from:

Using Plots

plot([0.0 1.0]',[0.0  -0.71]',label="Correct, solid blue with arrow",palette=:imola100,lw=2,arrow=true)
plot!([0.0 1.0]',[0.0 2.0]',label="Correct, solid black with arrow",palette=:grayC100,lw=2,arrow=true)
plot!([0.0 -1.076]',[0.0 3.78]',ls=:dash,label="Correct, dashed black with arror",palette=:grayC100,lw=2,arrow=true)
plot!([0.0 -2.076]',[0.0 3.78]',ls=:dash,label="Incorrect, why not dashed?",palette=:grayC100,lw=2,arrow=true) ####Why isn't this dashed?
plot!([0.0 -1.4]',[0.0  0.53]',ls=:dash,label="Incorrect, why not dashed?",palette=:imola100,lw=2,arrow=true) ####Why isn't this dashed?
plot!([0.0 -2.4]',[0.0  0.53]',ls=:dash,label="Inorrect, dashed but no arrow",palette=:imola100,lw=2) ####But it can be dashed with no arrow?

The legend suggests that the dashed lines are there but they are indistinguishable visually from solid lines. This is the case, when I zoom in, I see the dashes:

I thought it was just a visual issue and the dashes got merged together, so I removed the arrows

plot!([0.0 -1.4]',[0.0  0.53]',ls=:dash,palette=:imola100,lw=2) ####Why is this dashed?

and got dashes:
Screenshot 2024-02-23 101754

How can I make a dashed line with arrows work?

You may use the Plots.jl’s pyplot()/pythonplot() backend :

using Plots; pyplot(dpi=100)

plot([0.0, 1.0], [0.0, -0.71], c="blue", lw=2, arrow=true)
plot!([0.0, 1.0],[0.0, 2.0], c="red", lw=2, arrow=true)
plot!([0.0, -1.076], [0.0, 3.78], ls=:dash, c="orange", lw=2,arrow=true)
plot!([0.0, -2.076], [0.0, 3.78], ls=:dash, c="violet", lw=2,arrow=true)
plot!([0.0, -1.4], [0.0, 0.53], ls=:dash, c="green", lw=2, arrow=true)
plot!([0.0, -2.4], [0.0, 0.53], ls=:dash, c="grey", lw=2)

and submit an issue in Plots.jl repo for the gr() backend.

1 Like