![无法正确填充函数下方的区域](https://linux22.com/image/334066/%E6%97%A0%E6%B3%95%E6%AD%A3%E7%A1%AE%E5%A1%AB%E5%85%85%E5%87%BD%E6%95%B0%E4%B8%8B%E6%96%B9%E7%9A%84%E5%8C%BA%E5%9F%9F.png)
我不知道如何使用 TikZ 正确填充函数下方的区域(f 和 0 之间)。这是我的代码:
\begin{center}
\begin{tikzpicture}
\begin{axis}[
axis lines=left,
scaled ticks=false,
xticklabel style={
rotate=0,
anchor=east,
/pgf/number format/precision=0,
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
}, ]
\addplot[red,domain=0:15,samples=201, name path=A] {(25+x*(x-6)*(x-8)*(x-14)/25)*exp(sqrt(1+cos(deg(x^2/10))))};
\addplot[draw=none,domain=0:15,name path=B] {0}; % “fictional” curve
\addplot[thick, color=red, fill=red, fill opacity=0.1] fill between [of=A and B,soft clip={domain=0:15}]; % filling
\end{axis}
\end{tikzpicture}
\end{center}
非常感谢您的帮助 !
答案1
您可以为 X 轴(或 Y 轴)设置名称路径,因此无需额外的绘图命令。此外,移除软剪辑可修复填充。
输出
代码
\documentclass[margin=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=left,
scaled ticks=false,
xticklabel style={
rotate=0,
anchor=north,
/pgf/number format/precision=0,
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
},
x axis line style={name path=xaxis}
]
\addplot[red,domain=0:15,samples=201, name path=A] {(25+x*(x-6)*(x-8)*(x-14)/25)*exp(sqrt(1+cos(deg(x^2/10))))};
\addplot[thick, color=red, fill=red!50] fill between [of=A and xaxis]; % filling
\end{axis}
\end{tikzpicture}
\end{document}