如何在两条曲线之间着色?

如何在两条曲线之间着色?

在下面的代码中,我遇到了问题:

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

\pgfplotsset{compat=1.10}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}

    \begin{document}
    \begin{tikzpicture}
    \begin{axis}[axis lines=middle,
                xlabel=,
                ylabel=,
                enlargelimits,
                ytick=\empty,
                xtick={-1.19,2.38},
                xticklabels={$-1$,$2$}]
    \addplot[name path=F,blue,domain={-1.19:4}] {-(1/6)*x^2+2};
    
    \addplot[name path=G,green,domain={-3:4}] {0.25*x^2};
    
    \addplot[pattern=north west lines, pattern color=brown!50]fill between[of=F and G, soft clip={domain=-2.19:2.19}]
    ;
    \end{axis}
    \end{tikzpicture}
    \end{document}

在此处输入图片描述

答案1

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}
    \begin{document}
    \begin{tikzpicture}
    \begin{axis}[axis lines=middle,
                xlabel=,
                ylabel=,
                enlargelimits,
                ytick=\empty,
                xtick={-1.19,2.38},
                xticklabels={$-1$,$2$}]
    \addplot[name path=F,blue,domain={-2*sqrt(6/5):4}] {-(1/6)*x^2+2};
    \addplot[name path=G,green,domain={-2*sqrt(6/5):4}] {0.25*x^2};
    \tikzfillbetween[of=F and G, split, every segment no 0/.style={pattern=north west lines, pattern color=brown!50}, every segment no 1/.style={fill=none}] {};
\end{axis}
\end{tikzpicture}
\end{document}

两条曲线之间的填充图案

相关内容