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 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}
share|improve this question
    
there are y expr, x expr keys that uses the data in an expression. –  percusse Oct 31 '13 at 11:01

1 Answer 1

up vote 7 down vote accepted

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}
share|improve this answer

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.