我怎样才能隐藏这张图片中的两条线 y = 6 和 y = -4?

我怎样才能隐藏这张图片中的两条线 y = 6 和 y = -4?

我想隐藏 y = 6y = -4。我试过了line width=0pt,但不正确。我怎样才能隐藏那几行?我怎样才能减少我的代码?

\documentclass[a4paper, 12pt]{standalone}
\usepackage{fouriernc}
\usepackage{amsmath}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}
    [
    declare function={Y(\x)=(\x-1)/(\x+1);},
    axis lines = center,
    axis line style = very thick,
every axis x label/.style={
at={(ticklabel* cs:1.06)},anchor=east},
    xlabel=$x$,ylabel=$y$,
        domain=-6:8,
        ymin=-4,
        ymax=6,
        xmin=-6,
        xmax=4,
        xticklabels={},yticklabels={},
       unit vector ratio*=1 1 1,
    width=10cm,
    grid=major,
    grid style={gray!30}
    ]
\addplot [name path=A,blue, very thick,samples=100] {Y(x)};
\addplot [red, very thick] {1};
\addplot[name path=B,line width=0pt] {-4};
\addplot[name path=C,line width=0pt] {6};
       \node at (axis cs:-0.25, -0.25) {$O$} ;
     \addplot [black, mark = *] coordinates {(-1, 1)} ;

\addplot[pattern=north east lines] fill between[of=A and B,soft clip={domain=-0.55:4},];

\addplot[pattern=north east lines] fill between[of=A and C,soft clip={domain=-6:-1},];
       \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

相关选项是draw=none,所以

\addplot [name path=B, draw=none] {-4};

B添加一个名为您可以引用的路径,但没有绘制任何可见的内容。

示例输出

\documentclass[a4paper, 12pt]{standalone}
\usepackage{fouriernc}
\usepackage{amsmath}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}
    [
    declare function={Y(\x)=(\x-1)/(\x+1);},
    axis lines = center,
    axis line style = very thick,
    every axis x label/.style={
      at={(ticklabel* cs:1.06)},anchor=east},
    xlabel=$x$, ylabel=$y$,
    domain=-6:8,
    ymin=-4,
    ymax=6,
    xmin=-6,
    xmax=4,
    xticklabels={},yticklabels={},
    unit vector ratio*=1 1 1,
    width=10cm,
    grid=major,
    grid style={gray!30}
    ]
\addplot [name path=A,blue, very thick,samples=100] {Y(x)};
\addplot [red, very thick] {1};
\addplot [name path=B, draw=none] {-4};
\addplot [name path=C, draw=none] {6};
\node at (axis cs:-0.25, -0.25) {$O$} ;
\addplot [black, mark = *] coordinates {(-1, 1)} ;
\addplot[pattern=north east lines] fill between[of=A and B,soft clip={domain=-0.55:4},];
\addplot[pattern=north east lines] fill between[of=A and C,soft clip={domain=-6:-1},];
       \end{axis}
\end{tikzpicture}
\end{document}

顺便说一下,您已设置pgfplotscompat=1.9。当前版本是1.15

相关内容