我想使用此代码“平滑”获得的两条高斯曲线之间的区域:任何建议都将不胜感激。非常感谢。
\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
declare function={gauss(\x)=3*exp(-(\x/3)^2);},
scale = 0.6,
s/.style={shift=(0:9)}]
\fill [cyan!20]
plot[domain= -4:4, samples=100] (\x, {gauss(\x)})
{[s] -- plot[domain=-4:4, samples=100] (\x, {gauss(\x)})
|- (-8,0)}
-| cycle;
\filldraw[fill=pink!20, thick]
plot[domain=-4:4, samples=100] (\x, {gauss(\x)})
{[s] -- plot[domain=-4:4, samples=100] (\x, {gauss(\x)})
-- plot[domain=4:-4, samples=100] (\x, {gauss(\x)+0.2})}
-- plot[domain=4:-4, samples=100] (\x, {gauss(\x)+0.2})
-- cycle;
\path[fill=cyan!20] (-0.5,-2) -- (-0.5,0) -- (0.5,0) -- (0.5,-2) -- (-0.5,-2);
\path[fill=cyan!20] (8.5,-2) -- (8.5,0) -- (9.5,0) -- (9.5,-2) -- (8.5,-2);
\draw[black,thick] (0.5,-2) -- (0.5,0) -- (8.5,0) -- (8.5,-2);
\draw[black,thick] (-0.5,-2) -- (-0.5,0) -- (-4,0);
\draw[black,thick] (9.5,-2) -- (9.5,0) -- (13,0);
\draw [yshift=-0.25cm, -stealth](0,-1.5) -- node [fill=cyan!20,scale=0.55] {$Q_1$} (0,0);
\draw [yshift=-0.25cm, -stealth](9,-1.5) -- node [fill=cyan!20,scale=0.55] {$Q_2$} (9,0);
\node[scale=0.65] at (0,1.5) {${1}$};
\node[scale=0.65] at (9,1.5) {${2}$};
% \draw[very thick] (0:8) -- ++ (up:.6);
%\draw[fill=gray!20] (0.85,-1.5) -- (0.85,0) -- (15.15,0) -- (15.15,-1.5) -- (0.85,-1.5);
\end{tikzpicture}
\end{document}
答案1
为什么不直接将两个钟形曲线加在一起呢?
\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
declare function={gauss(\x)=3*exp(-(\x/3)^2);},
scale = 0.6,
s/.style={shift=(0:9)}]
\fill [cyan!20]
plot[domain= -4:13, samples=100] (\x, {gauss(\x)+gauss(\x-9})
|- (-4,0)
-| cycle;
\filldraw[fill=pink!20, thick]
plot[domain=-4:13, samples=100] (\x, {gauss(\x)+gauss(\x-9)})
-- plot[domain=13:-4, samples=100] (\x, {gauss(\x)+gauss(\x-9)+0.2})
-- cycle;
\path[fill=cyan!20] (-0.5,-2) -- (-0.5,0) -- (0.5,0) -- (0.5,-2) -- (-0.5,-2);
\path[fill=cyan!20] (8.5,-2) -- (8.5,0) -- (9.5,0) -- (9.5,-2) -- (8.5,-2);
\draw[black,thick] (0.5,-2) -- (0.5,0) -- (8.5,0) -- (8.5,-2);
\draw[black,thick] (-0.5,-2) -- (-0.5,0) -- (-4,0);
\draw[black,thick] (9.5,-2) -- (9.5,0) -- (13,0);
\draw [yshift=-0.25cm, -stealth](0,-1.5) -- node [fill=cyan!20,scale=0.55] {$Q_1$} (0,0);
\draw [yshift=-0.25cm, -stealth](9,-1.5) -- node [fill=cyan!20,scale=0.55] {$Q_2$} (9,0);
\node[scale=0.65] at (0,1.5) {${1}$};
\node[scale=0.65] at (9,1.5) {${2}$};
% \draw[very thick] (0:8) -- ++ (up:.6);
%\draw[fill=gray!20] (0.85,-1.5) -- (0.85,0) -- (15.15,0) -- (15.15,-1.5) -- (0.85,-1.5);
\end{tikzpicture}
\end{document}
答案2
改编
- 在中间添加了另一个图,重复使用高斯函数,然后缩放和移动它
plot[domain=-4:4, samples=100] (.125*\x+4.5, {3.39 - gauss(.15*\x)})
- 添加了一些代码注释
- 用于
rectange
在底部绘制蓝色矩形
代码
\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
declare function={gauss(\x)=3*exp(-(\x/3)^2);},
scale = 0.6,
s/.style={shift=(0:9)}
]
% double Gaussian
\fill [cyan!20]
plot[domain= -4:4, samples=100] (\x, {gauss(\x)})
-- plot[domain=-4:4, samples=100] (.125*\x+4.5, {3.39 - gauss(.15*\x)})
{[s] -- plot[domain=-4:4, samples=100] (\x, {gauss(\x)})
|- (-8,0)}
-| cycle;
% top curve
\filldraw[fill=pink!20, thick]
plot[domain=-4:4, samples=100] (\x, {gauss(\x)})
-- plot[domain=-4:4, samples=100] (.125*\x+4.5, {3.39 - gauss(.15*\x)})
{[s] -- plot[domain=-4:4, samples=100] (\x, {gauss(\x)})
-- plot[domain=4:-4, samples=100] (\x, {gauss(\x)+0.2})}
-- plot[domain=4:-4, samples=100] (.125*\x+4.5, {3.59 - gauss(.15*\x)})
-- plot[domain=4:-4, samples=100] (\x, {gauss(\x)+0.2})
-- cycle;
% bottom rectangle background
\path[fill=cyan!20] (-0.5,-2) rectangle (0.5,0);
\path[fill=cyan!20] (8.5,-2) rectangle (9.5,0);
% bottom
\draw[black,thick] (0.5,-2) -- (0.5,0) -- (8.5,0) -- (8.5,-2);
\draw[black,thick] (-0.5,-2) -- (-0.5,0) -- (-4,0);
\draw[black,thick] (9.5,-2) -- (9.5,0) -- (13,0);
% arrows
\draw [yshift=-0.25cm, -stealth](0,-1.5) -- node [fill=cyan!20,scale=0.55] {$Q_1$} (0,0);
\draw [yshift=-0.25cm, -stealth](9,-1.5) -- node [fill=cyan!20,scale=0.55] {$Q_2$} (9,0);
% numbers
\node[scale=0.65] at (0,1.5) {${1}$};
\node[scale=0.65] at (9,1.5) {${2}$};
\end{tikzpicture}
\end{document}