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 want to use in pgfplots \addplot plot cordinates with relative coordinates. However the following syntax doesn't work:

\documentclass{article}

\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
   \begin{axis}
      \addplot plot coordinates {(0,0) ++(2,2) ++(1,3)};
   \end{axis}
\end{tikzpicture}

\end{document}

How can I make this (or something similar) work?

share|improve this question
    
Related: tex.stackexchange.com/questions/73792/… –  student Sep 23 '12 at 18:04

1 Answer 1

up vote 6 down vote accepted

If you provide your data as a table instead of as a list of coordinates, you can use pgfplotstable to define a new column that consists of the accumulated x and y values:

enter image description here

\documentclass{article}

\usepackage{pgfplots, pgfplotstable}
\begin{document}

\pgfplotstableset{
    create on use/x rel/.style={
        create col/expr={
            \pgfmathaccuma + \thisrow{0}
        }
    },
    create on use/y rel/.style={
        create col/expr={
            \pgfmathaccuma + \thisrow{1}
        }
    }
}

\begin{tikzpicture}
    \begin{axis}
        \addplot table [x = x rel, y=y rel] {
      0 0
      2 2
      1 3
     };
   \end{axis}
\end{tikzpicture}

\end{document}
share|improve this answer
    
Thanks very much. When I add a % sign at the end of the table lines to prevent emacs to mash up my formatting, it doesn't compile. Do you have any tip for this? –  student Sep 23 '12 at 17:13
1  
You can add ignore chars=\% to the table options. –  Jake Sep 23 '12 at 17:15

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.