使用 pgfplots 绘制 arctan 时遇到问题

使用 pgfplots 绘制 arctan 时遇到问题

我尝试用 arctan(x) 进行绘图,pgfplots但没有得到好的输出。这是我的代码:

 \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}  

答案1

PGF 中的三角函数以度为单位,而不是弧度。您可以使用以下方式转换为弧度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}

相关内容