20
$\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$
  • $\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 Sep 28 '14 at 15:12
  • $\begingroup$ very closely related $\endgroup$ – bobthechemist Sep 28 '14 at 15:13
23
$\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$
  • 1
    $\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 Sep 28 '14 at 15:17
  • 1
    $\begingroup$ @Vaggelis_Z, you can use Arrowheads[{0, .05, .05, 0}]. $\endgroup$ – kglr Sep 28 '14 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 Jul 13 '16 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 Jul 13 '16 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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