Pgfplots 域异常

Pgfplots 域异常

如何断开“1/-0”和“1/0”

 \begin{center}
      \begin{tikzpicture}
        \begin{axis}[axis lines = middle, ymin = -10, ymax = 10, xmin = -5, xmax = 5]
          \addplot[color=red, samples = 100, domain=-5:5]{x^-1}
          node[right, pos=0.9]{$f(x)$};
        \end{axis}
      \end{tikzpicture}
    \end{center}

在此处输入图片描述

答案1

尝试

    \begin{tikzpicture}
\begin{axis}[
    axis lines = middle, 
    restrict y to domain=-30:30,   % <---
    ymin = -10, ymax = 10, 
    xmin = -5, xmax = 5,
    domain=-5:5,
    samples=101, no marks          % <---
    ]
\addplot {x^-1}    node[right, pos=0.9]{$f(x)$};
\end{axis}
    \end{tikzpicture}

在此处输入图片描述

相关内容