26
$\begingroup$

Let's consider the following case

f[x_] := x^2;
data = Table[{x, f[x]}, {x, -10, 10, 0.1}];
p0 = ListPlot[data, Frame -> True, Axes -> False, Joined -> True, 
     PlotStyle -> {Blue, Thick}]

In reality my data sets correspond to closed curves (loops), for which however the analytic equation is unknown. So, the solution should not take for granted that we know the exact mathematical expression.

Now I would like to add arrows inside the curve (which is produced by joining the points) thus showing the direction (from left to right), like this

enter image description here

Any suggestions?

$\endgroup$
2
  • $\begingroup$ Well is a closed loop the arrows can show you if the motion along the curve is clockwise or counterclockwise. The "left to right" notation is only for this simple example! $\endgroup$
    – Vaggelis_Z
    Commented Sep 28, 2014 at 15:12
  • $\begingroup$ very closely related $\endgroup$ Commented Sep 28, 2014 at 15:13

1 Answer 1

32
$\begingroup$
ClearAll[f, x, data];
f[x_] := x^2;
data = Table[{x, f[x]}, {x, -10, 10, 0.1}];
p0 = ListPlot[data, Frame -> True, Axes -> False, Joined -> True, 
   PlotStyle -> {Blue, Thick}];


p0 /. Line[x_] :> {Arrowheads[Table[.05, {5}]], Arrow[x]}

enter image description here

p0 /. Line[x_] :> {Arrowheads[{0, .05, .05, 0}], Arrow[x]}

enter image description here

or

Show[p0, BaseStyle -> Arrowheads[{0, .05, .05, 0}]] /. Line -> Arrow
(* same picture *)

You can also set the Arrowheads directive as part of the PlotStyle option:

ListPlot[data, Joined -> True, Frame -> True, Axes -> False, 
  PlotStyle -> {Blue, Thick, Arrowheads[{0, .05, .05, 0}]}] /.  Line -> Arrow

or, as the setting for BaseStyle

ListPlot[data, Joined -> True, Frame -> True, Axes -> False, 
  BaseStyle -> Arrowheads[{0, .05, .05, 0}], PlotStyle -> {Blue, Thick}] /. Line -> Arrow
$\endgroup$
4
  • 2
    $\begingroup$ What if I want only two as in the above plot? You use arrowheads but I don't want the am the start and end of the curve. $\endgroup$
    – Vaggelis_Z
    Commented Sep 28, 2014 at 15:17
  • 2
    $\begingroup$ @Vaggelis_Z, you can use Arrowheads[{0, .05, .05, 0}]. $\endgroup$
    – kglr
    Commented Sep 28, 2014 at 15:23
  • $\begingroup$ @kglr Hi, kglr. Why the arrows are not evenly distributed? You can try p0 /. Line[x_] :> {Arrowheads[Table[.05, {30}]], Arrow[x]} $\endgroup$
    – matheorem
    Commented Jul 13, 2016 at 3:21
  • $\begingroup$ @matheorem, good observation. I don't know why off the top of my head. This looks like a good question to post. $\endgroup$
    – kglr
    Commented Jul 13, 2016 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.