# Why do these two plot commands give different results?

Why the following two MWE codes, using pgfplots with and without gnuplot give different results (a phase shift)?

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\end{axis}
\end{tikzpicture}
\end{document}


and

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\end{axis}
\end{tikzpicture}
\end{document}

• atan gives its result already in degrees. I think you want to do cos(deg(2*x)+atan(1)). – Qrrbrbirlbel Sep 24 '13 at 23:48
• I get the same result in both cases. – Jake Sep 25 '13 at 7:21
• @Jake I get different results; what Qrrbrbirlbel proposes seems the right solution. – egreg Sep 25 '13 at 10:51

The PGFmath function atan (as well as all other trigonometrical functions) uses angles in degree (either as input or as output).

The deg function is used to convert an angle in radians in degrees. The correct way to write this function in PGFmath would be

cos(deg(2 * x) + atan(1))


or

cos(2 * deg(x) + atan(1)) = cos(2 * deg x + atan 1) = cos(2 * deg x + 45)


## Code

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[thick,domain=0:6, samples=1000]
\addplot [ultra thick] gnuplot {cos(    2*x  + atan(1) )};