12
$\begingroup$

If I got a bunch of numbers,then I can plot it with ListPlot:

{{1, 2}, {3, 9}, {7, 4}, {9, 9}}

 ListPlot[%, Joined -> True]

Then I get

enter image description here

Now I would like to have arrows in the middle of these lines, like this: enter image description here

Or maybe not in this way, but we got arrows in the end of each lines.

That's OK too.

If there is thousands of numbers like that, is there a simple way to add arrows like this?

Can anybody help me with that?

$\endgroup$

2 Answers 2

15
$\begingroup$
dt = {{1, 2}, {3, 9}, {7, 4}, {9, 9}};

Graphics[Arrow /@ Partition[dt, 2, 1], Frame -> Automatic]

enter image description here

Graphics[{Line @ dt, Arrow /@ Partition[dt, 2, 1] /. 
  {{a_, b_}, {c_, d_}} :> {{a, b}, {(a + c)/2, (b + d)/2}}}, 
    Frame -> Automatic]

enter image description here

Edit thanks to @J.M.

The above result (arrowheads in the middle) can be obtained more easily with

Graphics[{Arrowheads[{{.05, 0.5}}], Arrow /@ Partition[dt, 2, 1]},Frame -> Automatic]
$\endgroup$
1
  • 4
    $\begingroup$ You can use an Arrowheads[] specification to position the arrowheads in the middle of the segments. $\endgroup$ Commented Oct 25, 2015 at 14:06
11
$\begingroup$

Here is an interactive way you could place arrowheads,e.g second row could be copied and pasted into function once desired placement was achieved.

lst = {{1, 2}, {3, 9}, {7, 4}, {9, 9}};
Manipulate[
 Column[{ListPlot[lst, Joined -> True] /. 
    Line[x__] :> {Arrowheads[ {{ah, ahp1}, {ah, ahp2}, {ah, ahp3}}], 
      Arrow[x]},
   {{ah, ahp1}, {ah, ahp2}, {ah, ahp3}}
   }]
 , {ah, 0.05, 0.2}, {ahp1, 0, 1}, {ahp2, 0, 1}, {ahp3, 0, 1}]

enter image description here

$\endgroup$

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.