[Tex/LaTex] PGFPlots: How to shift the values read from the file

pgfplotstikz-pgf

I have a plot that reads the values from a file. Now I want to shift the values in the file. Is it possible with builtin methods of PGFPlots? I want something like the shift function:

\begin{tikzpicture}
    \begin{axis}[
                width=\textwidth,
                height=8cm,
                xlabel={$t~[s]$},
                ylabel={$u$},
                legend entries={a,b},
                ymin=-10,
                ymax=10,
                enlarge x limits=false
    ]
         \addplot+[shift={(-10,5)}] file {data.dat};
    \end{axis}  
\end{tikzpicture}

Best Answer

If I understand correctly what do you mean by "shift", you can use the x expr and y expr options like this:

\documentclass{article}
\usepackage{pgfplots,filecontents}
\pgfplotsset{compat=newest}

\begin{filecontents}{data.dat}
1   2
2   4
3   6
4   8
5   10
\end{filecontents}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
                    width=\textwidth,
                    height=8cm,
                    xlabel={$t~[s]$},
                    ylabel={$u$},
                    legend entries={a,b},
                    enlarge x limits=false
        ]
             \addplot table [x expr=\thisrowno{0}-10,y expr=\thisrowno{1}+5] {data.dat};
        \end{axis}  
    \end{tikzpicture}
\end{document}