我有一个蒂克兹像这样的图片:
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xmin=-0.5,xmax=3.5,ymin=-0.5,ymax=3.5
]
\addplot[very thick,blue, samples=300, domain=0:3, name path=A] {sqrt(x)};
\addplot[very thick,yellow!70!red, samples=300, domain=0:3, name path=B] {9-3*x};
\addplot[very thick,red!90!teal, samples=300, domain=0:3, name path=C] {3};
\addplot[very thick,green!70!magenta, samples=300, domain=0:3, name path=D] coordinates{(1/9,-6) (1/9,6)};
\end{axis}
\end{tikzpicture}
我想填充这四条曲线所围起的区域。
pgfplots
使用的包已经回答了类似的问题fillbetween
,但它似乎只支持在二曲线。我有什么选择?
答案1
这里有一个解决方法,你可以将区域分为两部分:第一部分在曲线 A 和 C 之间,第二部分在 A 和 B 之间,并用于soft clip
限制填充
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xmin=-0.5,xmax=3.5,ymin=-0.5,ymax=3.5
]
\addplot[very thick,blue, samples=300, domain=0:3, name path=A] {sqrt(x)};
\addplot[very thick,yellow!70!red, samples=300, domain=0:3, name path=B] {9-3*x};
\addplot[very thick,red!90!teal, samples=300, domain=0:3, name path=C] {3};
\addplot[very thick,green!70!magenta, samples=300, domain=0:3, name path=D] coordinates{(1/9,-6) (1/9,6)};
\addplot[gray!30] fill between[of=A and C,soft clip={domain=1/9:2}];
\addplot[gray!30] fill between[of=A and B,soft clip={domain=2:2.5}];
\end{axis}
\end{tikzpicture}
\end{document}