我想要绘制的是 3 个函数:x=0、y=0 和 x=cos^{-1}(x)。
前两个的情节和图表如下所示:
\begin{center}
\begin{tikzpicture}
\begin{axis}[domain = -1:1, samples = 500, grid = both]
\addplot[color = red](0, x);
\addlegendentry{$x=0$}
\addplot[color = green]{0};
\addlegendentry{$y=0$}
\end{axis}
\end{tikzpicture}
\end{center}
然后我添加第三个:
\begin{center}
\begin{tikzpicture}
\begin{axis}[domain = -1:1, samples = 500, grid = both]
\addplot[color = red](0, x);
\addlegendentry{$x=0$}
\addplot[color = green]{0};
\addlegendentry{$y=0$}
\addplot[color = blue] {acos(x)};
\addlegendentry{$\cos^{-1}(x)$}
\end{axis}
\end{tikzpicture}
\end{center}
一切都变得一团糟。这是为什么呢?
答案1
水平域给人的印象是没有任何变化,但是因为您突然将垂直轴增加到 150 而domain=-1:1
变得不可见。
另外,您使用 500 个样本绘制恒定图。请单独提供,这里是 130
\begin{tikzpicture}
\begin{axis}[grid = both,samples=2]
\addplot[draw= red,ultra thick,domain=-1:1]{0};
\addlegendentry{$x=0$}
\addplot[draw = green,ultra thick,domain=-1:130] (0,x);
\addlegendentry{$y=0$}
\addplot[draw = blue,samples = 101,domain = -1:1] {acos(x)};
\addlegendentry{$\cos^{-1}(x)$}
\end{axis}
\end{tikzpicture}
答案2
事实证明,pgfplots
(我认为底层 PGF 也是如此)将三角函数的输入视为度数,而不是弧度。您可以通过键强制将其设置为弧度trig format=rad
。这还可以解决您的 y 域问题:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{tikzpicture}
\begin{axis}[domain = -1:1, samples = 500, grid = both]
\addplot[color = red](0, x);
\addlegendentry{$x=0$}
\addplot[color = green]{0};
\addlegendentry{$y=0$}
\addplot[color = blue, trig format=rad] {acos(x)};
\addlegendentry{$\cos^{-1}(x)$}
\end{axis}
\end{tikzpicture}
\end{document}