[Tex/LaTex] Incorrect plot using pgfplots (trigonometric functions like cos, sin and tan)

pgfplots

I'm trying to plot a function with pgfplots for LaTeX. Unfortunately, pgfplots plots the function incorrectly. Here is the LaTeX code I use:

\begin{figure}[H]
\centering
\begin{tikzpicture}
    \begin{axis}[xlabel=Gameplays,ylabel=Rating]
        \addplot+[gray,domain=1:30]
        {0.5 + 0.5 * ((atan(x) * 2 / pi)^11.79)};
    \end{axis}
\end{tikzpicture}
\caption{Omzetten van aantal gameplays tot impliciete rating}
\label{fig:omzetten_impliciete_ratings}
\end{figure}

Here is how the function should look like:

This is how it is plotted:

Does anyone know what I do wrong?

Thanks in advance!

Best Answer

TikZ uses degrees instead of radians (yes, yes, I know ...). So you need to replace pi by 180 (or, as Jake suggests in the comments, replace atan(x) by rad(atan(x)); the rad function converts degrees to radians).

\documentclass{minimal}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[xlabel=Gameplays,ylabel=Rating]
        \addplot+[gray,domain=1:30]
        {0.5 + 0.5 * ((atan(x) * 2 / 180)^11.79)};
    \end{axis}
\end{tikzpicture}
\end{document}

This produces:

PGFPlots with degrees

which looks a lot more like what you want (the numbers on your graph are a little small for me so I compared with the output I get from gnuplot using your function and it looks right when compared with that).