5
$\begingroup$

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?

$\endgroup$
7
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ Aha! Now to go and learn about RuleDelayed. Many thanks. $\endgroup$ – Cameron Murray Dec 6 '13 at 3:55
4
$\begingroup$

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

$\endgroup$
2
$\begingroup$

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

$\endgroup$
0
$\begingroup$
ListLinePlot[Range[10]^2]/.Line[x__]:>{Arrowheads[Table[.05,10]],Arrow[x]}

$\endgroup$

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.