Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to draw a plot and put arrow heads pointing in the direction of the plot instead of marks.

My first idea was to use the quiver option from pgfplots by duplicating and stagering the columns of my data table. I was not succesful with thisowever. In addition, this require some additional manipulation and is not very felxible if it becomes, for instance, necessary to draw only a fex arrows.

My second idea was to get the nodes and draw a tikz path. i thought about nodes near coord but did not find any means to retreive the nodes names outside the axis command.

I ended up with the following code using decoration (as in this question) :

\documentclass{article}
\usepackage{pgfplots}

 \usetikzlibrary{decorations.markings}

\begin{document}
\pgfplotstableread {%
1 0
0.9424764947 0.07142857143
0.8807513856 0.1428571429
0.814278019 0.2142857143
0.7433146111 0.2857142857
0.6680059078 0.3571428571
0.5883915727 0.4285714286
0.5054583078 0.5
0.4203175805 0.5714285714
 0.3328127843 0.6428571429
 0.2485549667 0.7142857143
 0.1694124286 0.7857142857
 0.09704848952 0.8571428571
 0.03951561078 0.9285714286
 0 1
}\table
\begin{tikzpicture}[baseline, trim axis left, trim axis right]
  \pgfplotsset{ref/.style={mark=o}}
  \begin{axis}
    \addplot[ref] table[x index=0, y index=1] {\table}
    [postaction={decorate, decoration={markings,
        mark=between positions 1/15 and 1 step 1/15 with {\arrow[red,line width=.5pt]{>};}
      }}]
    ;

  \end{axis}
\end{tikzpicture}

\end{document}

Here is the result:

red arros should take place of circles

The problem is to get the red arrows where the circles are. How could this be done?


The two following question are related but my main problem her is more to get the nodes from the table input.

Decorate path with arrows at nodes

How to decorate a path with arrows at certain coordinates?


The following question that I asked to solve a different problem happens to be applicable here:

naming-the-nodes-of-nodes-near-coords

Indeed, once the node are names, some pgf path can be traced to link them.

share|improve this question
    
For this to work you need a uniformly seperated x coordinate grid. So a better thing would be coming up with a new plotmark. –  percusse Oct 3 '12 at 12:30
    
The problem would be to have the right orientation for each plotmark. –  Alfred M. Oct 3 '12 at 12:35

1 Answer 1

up vote 3 down vote accepted

I see you aren't using any smoothing algorithm, so each arrow line is parallel to each line segment. Then, instead of drawing a polygonal chain, you can draw many arrow lines connected each other (pgfplots supports Ti*k*Z arrow styles). To do this, you need to select two consecutive rows at a time from the table, by means of pgfplotstable commands.

\documentclass{article} 
\usepackage{pgfplots} 

\begin{document} 
\pgfplotstableread {% 
1 0 
0.9424764947 0.07142857143 
0.8807513856 0.1428571429 
0.814278019 0.2142857143 
0.7433146111 0.2857142857 
0.6680059078 0.3571428571 
0.5883915727 0.4285714286 
0.5054583078 0.5 
0.4203175805 0.5714285714 
0.3328127843 0.6428571429 
0.2485549667 0.7142857143 
0.1694124286 0.7857142857 
0.09704848952 0.8571428571 
0.03951561078 0.9285714286 
0 1 
}\table

\pgfplotstablegetrowsof{\table} 
\pgfmathsetmacro{\rows}{\pgfplotsretval-2}

\begin{tikzpicture} [baseline, trim axis left, trim axis right] 
\begin{axis}
\foreach \k in {0,...,\rows}
  {
   \pgfplotstablegetelem{\k}{[index]0}\of\table 
   \let\x\pgfplotsretval
   \pgfplotstablegetelem{\k}{[index]1}\of\table 
   \let\y\pgfplotsretval
   \pgfmathsetmacro{\K}{\k+1}
   \pgfplotstablegetelem{\K}{[index]0}\of\table 
   \let\X\pgfplotsretval
   \pgfplotstablegetelem{\K}{[index]1}\of\table 
   \let\Y\pgfplotsretval
   \addplot [blue,->] coordinates {(\x,\y) (\X,\Y)};
  }
\end{axis} 
\end{tikzpicture} 
\end{document}

enter image description here

As \k goes from the 0th to the second last line of the table, \K goes from the 1th to the last, so that you can draw n-1 consecutive arrow segments. At each step, you get the coordinates of the starting point (\x,\y) and those of the ending point (\X,\Y), then you draw an arrow segment.

Maybe there is a faster, simpler and more elegant way of doing this, but I don't know it.

share|improve this answer
    
Your solution is not that kludgy and compile quite fast assuming that there are not too much points. Thanks ! –  Alfred M. Oct 5 '12 at 9:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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