5

I'm trying to plot arctan(x) with pgfplots but I don't get a good output. Here is my code:

 \begin{cfigur}\begin{axis}[
     width=160pt,compat=1.5.1,grid style={ultra thin},every axis plot post/.append style={thick},
     x tick label style={font=\tiny},y tick label style={font=\tiny},
     scale only axis,grid=major,axis lines=middle,
     xlabel={$x$},
     ylabel={$y$},
     xmin=-200,
     xmax=200,
     domain=-200:210,
     ymin=-5.5,
     ymax=5.5,
     xtick={-150,-100,...,150},
     ytick={-5, -4,...,5},
     restrict y to domain=-20:20,
     legend style={at={(0.5,-0.05)},anchor=north,nodes={right}},
 ]
 \addplot[mark=none,color=blue, samples=500]{atan(x)};
 \addlegendentry{$y = \tan^{-1}x $};
 \end{axis}\end{cfigur}  
jub0bs
  • 58,916
Henrik
  • 647
  • You can format code sections by selecting and then using the {} button in the editor (which simply indents by four spaces) but please always make a complete document starting \documentclass and all loading needed packages, so people can test their answers. – David Carlisle Feb 17 '14 at 20:38

1 Answers1

11

The trigonometric functions in PGF work with degrees, not radians. You can convert to radians using rad(...):

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\pgfplotsset{compat=1.9}
\begin{tikzpicture}
\begin{axis}[
     width=160pt,compat=1.5.1,grid style={ultra thin},every axis plot post/.append style={thick},
     x tick label style={font=\tiny},y tick label style={font=\tiny},
     scale only axis,grid=major,axis lines=middle,
     xlabel={$x$},
     ylabel={$y$},
     xmin=-200,
     xmax=200,
     domain=-200:210,
     ymin=-5.5,
     ymax=5.5,
     xtick={-150,-100,...,150},
     ytick={-5, -4,...,5},
     restrict y to domain=-20:20,
     legend style={at={(0.5,-0.05)},anchor=north,nodes={right}},
 ]
 \addplot[mark=none,color=blue, samples=500]{rad(atan(x))};
 \addlegendentry{$y = \tan^{-1}x $};
 \end{axis}
\end{tikzpicture}

\end{document}
Jake
  • 232,450