5

Is it possible to use the Meshstyle option of the PlotMarkers option in ListLinePlot to have Arrowheads as a point marker, obviously pointing in the positive direction of the line at that point? Using the example below, what sort of function would I need in the MeshStyle option.

ListLinePlot[Range[10]^2]

If not, what alternative solution might exist?

Cameron Murray
  • 921
  • 7
  • 16

4 Answers4

9

A quite simple solution is to replace the Line directives with Arrow. Sine there is usually only one Line directive, you have to partition the list of points manually:

ListLinePlot[Range[10]^2] /.  Line[pts_] :> (Arrow /@ Partition[pts, 2, 1])

Mathematica graphics

halirutan
  • 112,764
  • 7
  • 263
  • 474
5

what sort of function would I need in the MeshStyle option

You can place arrows on the line using Mesh, MeshFunctions and MeshShading options:

ListLinePlot[Sin@Range[0, 4 Pi, 4 Pi/50], 
  MeshFunctions -> {#2 &}, Mesh -> 6, MeshStyle -> Opacity[0], 
  MeshShading -> {Arrowheads[Medium]}, DataRange -> {0, 4 Pi}] /. Line -> Arrow

enter image description here

Using

MeshShading -> {Directive[Arrowheads[Small], Dotted, Red], 
  Directive[Arrowheads[Medium], Blue]}

we get

enter image description here

Using different setting for MeshFunctions:

ListLinePlot[Range[-10, 10]^2, MeshFunctions -> {"ArcLength"}, 
  Mesh -> 20, MeshStyle -> Opacity[0], 
  MeshShading -> {Arrowheads[Medium]}, DataRange -> {-10, 10}, 
  AspectRatio -> 1] /. Line -> Arrow

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
2

For function plotting:

f[x_] := x^2; (* define a function to plot *)
df = 1/4; (* define a step size for the arrows *)

g[x_] := Sin[x];
dg = Pi/16;

{
 Plot[f[x], {x, -5, 5}, Epilog -> Table[{Red, AbsolutePointSize[3],
     Arrow[{{i - df, f[i - df]}, {i + df, f[i + df]}}]
     }, {i, -5, 5, 2 df}], ImageSize -> 300],
 Plot[g[x], {x, 0, 6 Pi}, Epilog -> Table[{Red, AbsolutePointSize[3],
     Arrow[{{i - dg, g[i - dg]}, {i + dg, g[i + dg]}}]
     }, {i, 0, 6 Pi, 2 dg}], ImageSize -> 300]
 }

Mathematica graphics

István Zachar
  • 47,032
  • 20
  • 143
  • 291
0
ListLinePlot[Range[10]^2]/.Line[x__]:>{Arrowheads[Table[.05,10]],Arrow[x]}

yode
  • 26,686
  • 4
  • 62
  • 167