25

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?

Vaggelis_Z
  • 8,740
  • 6
  • 34
  • 79

1 Answers1

30
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
kglr
  • 394,356
  • 18
  • 477
  • 896
  • 2
    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. – Vaggelis_Z Sep 28 '14 at 15:17
  • 2
    @Vaggelis_Z, you can use Arrowheads[{0, .05, .05, 0}]. – kglr Sep 28 '14 at 15:23
  • @kglr Hi, kglr. Why the arrows are not evenly distributed? You can try p0 /. Line[x_] :> {Arrowheads[Table[.05, {30}]], Arrow[x]} – matheorem Jul 13 '16 at 03:21
  • @matheorem, good observation. I don't know why off the top of my head. This looks like a good question to post. – kglr Jul 13 '16 at 07:25