함수의 두 모서리로 직사각형을 채우는 방법

함수의 두 모서리로 직사각형을 채우는 방법

다음 그림에서 모든 기능에 대해 동일한 내용을 적용하고 싶습니다.

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

현재 내 코드는 다음과 같습니다(여기 Tex.sx에 있는 일부 게시물의 편집된 버전입니다). 곡선 아래만 완전히 채워집니다!

\documentclass[11pt,bezier]{article}
\usepackage{xstring}
\usepackage{collcell}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\begin{document}
\begin{figure}[ht!]
    \centering
    \begin{tikzpicture}
        \begin{axis}[xmin=-1,xmax=9,xlabel={Y},ymin=0,ymax=10] 
        \addplot[color=black,domain=-1:9,samples=100]
            {(-(x-3)^2+(x-3)^4-(x-1)^3+4)/40+5};
        \addplot[color=black,fill=lime,  domain=5.8:7,samples=100]
            {(-(x-3)^2+(x-3)^4-(x-1)^3+4)/40+5} \closedcycle;
        \end{axis}
    \end{tikzpicture}
    \end{figure}
\end{document}

답변1

상대 좌표 및 --cycle(대신 \closedcycle)을 사용하여 다음을 얻을 수 있습니다.

\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[xmin=-1,xmax=9,xlabel={Y},ymin=0,ymax=10] 
        \addplot[color=black,domain=-1:9,samples=100] {(-(x-3)^2+(x-3)^4-(x-1)^3+4)/40+5};
        \addplot[color=black,fill=lime,  domain=5.8:7,samples=100] 
            {(-(x-3)^2+(x-3)^4-(x-1)^3+4)/40+5} -- +(axis direction cs:-1.2,0)--cycle;
        \addplot[color=black,fill=cyan,  domain=7:5.8,samples=100] 
            {(-(x-3)^2+(x-3)^4-(x-1)^3+4)/40+5} -- +(axis direction cs:1.2,0)--cycle;
        \end{axis}
    \end{tikzpicture}
\end{document}

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

관련 정보