# Use pgfplots \addplot plot coordinates with relative coordinates

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?

• Sep 23 '12 at 18:04

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:

\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}

• 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? Sep 23 '12 at 17:13
• You can add ignore chars=\% to the table options.
– Jake
Sep 23 '12 at 17:15