我有一个使用 tikz 的正态分布函数,我无法填充曲线下的区域。
这是我的最小代码:
\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\tikzset{declare function={myGauss(\x,\y,\z)=exp(-(\x-\y)*(\x-\y)/(\z*\z));}}
% this is a Gaussian centered at \y with a width controlled by \z
\begin{tikzpicture}
\draw [thick] (0,0)--(5,0);
\foreach \x in {0,...,5}
\draw[xshift=\x cm, thick] (0pt,-1pt)--(0pt,1pt) node[below] {$\x$};
\draw plot[fill=red,domain=0:5,variable=\x,samples=100] ({\x},{myGauss(\x,4.24,0.43)});
\end{tikzpicture}\par
\end{document}
我想在正态分布曲线下创建一个实心填充,但一直没有成功。任何帮助都将不胜感激。谢谢。
答案1
\documentclass[tikz,margin=10pt]{standalone}
\begin{document}
\tikzset{declare function={myGauss(\x,\y,\z)=exp(-(\x-\y)*(\x-\y)/(\z*\z));}}
% this is a Gaussian centered at \y with a width controlled by \z
\begin{tikzpicture}
\def\mygaussian{plot[domain=0:5,variable=\x,samples=100] ({\x},{myGauss(\x,4.24,0.43)})}
\fill[cyan] (0,0) \mygaussian -- (5,0) -- cycle ;
\draw \mygaussian;
\draw [thick] (0,0)--(5,0);
\foreach \x in {0,...,5}
\draw[xshift=\x cm, thick] (0pt,-1pt)--(0pt,1pt) node[below] {$\x$};
\end{tikzpicture}
\end{document}