我正在尝试在 tikz 中绘制 |xy|=2。请考虑这个 MWE
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}% coordinates
\begin{axis}[
axis lines=middle,
ymax=3, ymin=-3, ylabel={$y$},
xmax=3, xmin=-3, xlabel={$x$},
ytick distance=1,
xtick distance=1
]
\end{axis}
\end{tikzpicture}
\end{document}
当我这样做的时候
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}% coordinates
\begin{axis}[
axis lines=middle,
ymax=3, ymin=-3, ylabel={$y$},
xmax=3, xmin=-3, xlabel={$x$},
ytick distance=1,
xtick distance=1
]
\addplot{abs(x*y)=2};
\end{axis}
\end{tikzpicture}
\end{document}
我最终遇到这个错误:Package PGF Math Error: Unknown operator
='或=2' (in 'abs(x*y)=2'). \addplot{abs(x*y)=2};
答案1
pgf
无法绘制隐式方程。对于大多数隐式方程,这个问题无法解决。不过,对于你的情况,我们只需要求解y=±2/x
(同时考虑域中的奇异性):
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}% coordinates
\begin{axis}[
axis lines=middle,
ymax=3, ymin=-3, ylabel={$y$},
xmax=3, xmin=-3, xlabel={$x$},
ytick distance=1,
xtick distance=1
]
\addplot[domain=-3:-.3]{2/x};
\addplot[domain=.3:3]{2/x};
\addplot[domain=-3:-.3]{-2/x};
\addplot[domain=.3:3]{-2/x};
\end{axis}
\end{tikzpicture}
\end{document}