8

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!

Jan
  • 175
  • 2
  • 6
  • Hi @Jan, welcome to tex.sx. Note that you original question was now migrated to this site. You might want to connect your stackoverflow.com account with your tex.sx account. You can do at your user page. I'm closing the other one for now. – Martin Scharrer Mar 08 '11 at 13:44

3 Answers3

16

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).

Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751
15

This is old but I found it when I had the same problem. Now there is a new solution called trig format plots=rad.

\begin{axis}[trig format plots=rad]
...

See the manual section 4.3.3 Computing Coordinates with Mathematical Expressions.


Just for search engines: pgfplots, trigonometric functions, radian, degree, wrong result, wrong plot

4

Only for information. This is not an answer but I try your function with tkz-fct (tkz-fct works with tikz and gnuplot).

pgfplots is more complete and sophisticated package than tkz-fct.

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{tkz-fct}

\begin{document}

\begin{center}
\begin{tikzpicture}
        \tkzInit[xmin=0,xmax=30,,xstep=5,
                 ymin=0.4,ymax=1,ystep=0.1]
        \tkzAxeXY 
        \tkzGrid
        \tkzFct[domain=1:30]{0.5 + 0.5 * ((atan(\x) * 2 / pi)**11.79) }
\end{tikzpicture}
\end{center}

\end{document

}

enter image description here

Alain Matthes
  • 95,075