我不知道如何使用 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}