How do I graph a line in Julia with an arrow on both sides?

Advertisements

Here is my code:

using MTH229
using Plots
f(x)=x
theme(:dark)
plot(f,-5,5,linewidth=5,c=:hotpink,legend=false,arrow=true)

Here is a picture of the output:

plot

How do I get the arrow to appear on both ends of the line instead of just one?

>Solution :

It’s a bit of a hacky solution, but for the example in the question:

plot!([-4.99,-5],[f(-4.99), f(-5)],
  linewidth=5,c=:hotpink,legend=false,arrow=true)

adds the reverse arrow. Generalizing to any chart is pretty straight forward. The idea is to draw a line chart with a reverse direction, for just a tiny bit at the location of the reverse arrow and let Plot add the reverse arrow.

Leave a Reply Cancel reply