如何用 TikZ 绘制高斯演变?

如何用 TikZ 绘制高斯演变?

如何用 TikZ 绘制高斯演变? 在此处输入图片描述

我已经从这个代码开始

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[every axis plot post/.append style={
  mark=none,domain=-3:3,samples=50,smooth},
clip=false,
axis y line=none,
axis x line*=bottom,
ymin=0,
xtick=\empty]


\addplot +[shift={(600,-0)},line width=3pt, rotate= -180, scale =4.2] {\gauss{0}{1.6}};

\addplot +[shift={(600,-100)},line width=3pt, rotate= -180] {2.*\gauss{0}{1.6}};

\addplot +[shift={(600,-150)},line width=3pt, rotate= -180] {\gauss{0}{1.6}};

\addplot +[shift={(600,-200)},line width=3pt, rotate= -180] {\gauss{0}{1.6}};
\end{axis}
\end{tikzpicture}

\end{document}

答案1

这是使用该库的方法intersections。代码中有一些注释,如果有什么不清楚的地方可以询问。一些标签的定位可以微调。

在此处输入图片描述

\documentclass[margin=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\pgfmathdeclarefunction{gauss}{3}{% #1=mean, #2=width, #3=x
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((#3-#1)^2)/(2*#2^2))}%
}

\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=none,
xtick=\empty,
every axis plot/.append style={line width=3pt,no marks},
domain=-6:6,
samples=50
]

% width of gaussians
\newcommand\sigmaA{1.6}
\newcommand\sigmaB{2}
\newcommand\sigmaC{2.5}
% vertical offsets of second and third gaussians
\newcommand\offsetB{0.16}
\newcommand\offsetC{0.3}

% plot gaussians
\addplot +[name path=a] {-gauss(0,\sigmaA,x)} node[pos=0.5,below] {$W_{\max}$};
\addplot +[name path=b] {-gauss(0,\sigmaB,x) - \offsetB} node[pos=0.5,below] {$W_{\max}$};
\addplot +[name path=c] {-gauss(0,\sigmaC,x) - \offsetC} node[pos=0.5,below] {$W_{\max}$};

% draw (invisible) horizontal paths at y=half maximum
\addplot [draw=none,name path=l1,samples=2] {-gauss(0,\sigmaA,0)/2};
\addplot [draw=none,name path=l2,samples=2] {-gauss(0,\sigmaB,0)/2 - \offsetB};
\addplot [draw=none,name path=l3,samples=2] {-gauss(0,\sigmaC,0)/2 - \offsetC};

% find intersections between gaussians and horizontal paths, draw line between them
\draw [thick] [name intersections={of=a and l1,name=A}] (A-1) -- (A-2) node[right] {$W_{\max}/2$};
\draw [thick] [name intersections={of=b and l2,name=B}] (B-1) -- (B-2) node[right] {$W_{\max}/2$};
\draw [thick] [name intersections={of=c and l3,name=C}] (C-1) -- (C-2) node[right] {$W_{\max}/2$};

% draw extended lines from first to last of the intersections defined above
\draw [thick, dashed,shorten >=-2cm,shorten <=-2cm] (A-1) -- (C-1);
\draw [thick, dashed,shorten >=-2cm,shorten <=-2cm] (A-2) -- (C-2);

\end{axis}
\end{tikzpicture}

\end{document}

相关内容