곡선 사이의 음영 영역에서는 소프트 클립이 작동하지 않습니다.

곡선 사이의 음영 영역에서는 소프트 클립이 작동하지 않습니다.

곡선 사이의 영역을 음영 처리하는 방법을 찾으려고 노력했지만 소프트클립을 사용하여 LaTeX에서 코딩을 시도하면 모든 것이 종료됩니다. 어떻게 해야할지 모르겠습니다.

이것은 내 코드입니다.

\documentclass[tikz, border=2mm]{standalone}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[
    grid=both,
    axis lines=middle,
    xmin=-2, xmax=5,
    ymin=-5, ymax=10,
    xlabel={$x$},
    ylabel={$y$},
    legend style={at={(0.5,-0.15)}, anchor=north},
    ]

    \addplot[blue, domain=-2:5, samples=100, name path=A] {x^2 - 2*x};
    \addlegendentry{$y = x^2 - 2x$}

    \addplot[red, domain=-2:5, samples=100, name path=B] {4*x - x^2};
    \addlegendentry{$y = 4x - x^2$}

    % Create a path for the shaded region
    \path[name path=zero] (0,0) -- (0,8);

    % Shade the region between the two functions in red
    \addplot[red, fill, opacity=0.3] fill between[of=A and B, soft clip={domain=0:3}] \closedcycle;

  \end{axis}
\end{tikzpicture}

\end{document}

답변1

코드를 실행하려고 하면 다음 메시지가 표시됩니다. ! Package pgfplots Error: 'name path' is undefined. Please load \usetikzlibrary {intersections} or \usepgfplotslibrary{fillbetween}.

그래서 나는 그렇게 했습니다. \usepgfplotslibrary{fillbetween}서문에 삽입했습니다 . 이제는 나에게 완벽하게 작동하는 것 같습니다.

\documentclass[tikz, border=2mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\begin{document}

\begin{tikzpicture}
  \begin{axis}[
    grid=both,
    axis lines=middle,
    xmin=-2, xmax=5,
    ymin=-5, ymax=10,
    xlabel={$x$},
    ylabel={$y$},
    legend style={at={(0.5,-0.15)}, anchor=north},
    ]

    \addplot[blue, domain=-2:5, samples=100, name path=A] {x^2 - 2*x};
    \addlegendentry{$y = x^2 - 2x$}

    \addplot[red, domain=-2:5, samples=100, name path=B] {4*x - x^2};
    \addlegendentry{$y = 4x - x^2$}

    % Create a path for the shaded region
    \path[name path=zero] (0,0) -- (0,8);

    % Shade the region between the two functions in red
    \addplot[red, fill, opacity=0.3] fill between[of=A and B, soft clip={domain=0:3}] \closedcycle;

  \end{axis}
\end{tikzpicture}

\end{document}

이것이 당신이 원했던 것이라면...

여기에 이미지 설명을 입력하세요

관련 정보