関数の2つの角を持つ長方形を塗りつぶす方法

関数の2つの角を持つ長方形を塗りつぶす方法

次の図と同じことを任意の関数に適用できるようにしたいと思います。

ここに画像の説明を入力してください

現在、私のコードは次のようになります (これは 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}

ここに画像の説明を入力してください

関連情報