Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Chart with reverse arrow

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading