我想要得到这个显示高斯曲线的颜色和“sigma”相关值的图:
以下是我目前所掌握的信息:
\documentclass[11pt]{book}
\usepackage{pgfplots}
\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
no markers,
domain=-6:6,
samples=100,
axis lines*=left,
xlabel=$x$,
ylabel=$G(x)$,
% every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
height=5cm, width=12cm,
%xtick=\empty,
%ytick=\empty,
enlargelimits=false, clip=false, axis on top,
grid = major,
]
\addplot [very thick,blue!50!black] {gauss(0,1.5)};
\end{axis}
\end{tikzpicture}
\caption{Bell Shaped Gaussian Distribution}
\end{center}
\end{figure}
\end{document}
答案1
\documentclass[11pt]{book}
\usepackage{pgfplots}
\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
no markers,
domain=-6:6,
samples=100,
axis lines*=left,
xlabel=$x$,
ylabel=$G(x)$,
every axis x label/.style={at=(current axis.right of origin),anchor=west},
height=5cm, width=12cm,
enlargelimits=false, clip=false, axis on top,
grid = major,
xtick={-6,-4.5,...,6},
xticklabels={,$-3\sigma$,$-2\sigma$,$-1\sigma$,$\mu$,$1\sigma$,$2\sigma$,$3\sigma$,},
]
\addplot [fill=gray, draw=none, domain=-6:-4.5] {gauss(0,1.5)} \closedcycle;
\addplot [fill=green, draw=none, domain=-4.5:-3] {gauss(0,1.5)} \closedcycle;
\addplot [fill=brown, draw=none, domain=-3:-1.5] {gauss(0,1.5)} \closedcycle;
\addplot [fill=blue, draw=none, domain=-1.5: 1.5] {gauss(0,1.5)} \closedcycle;
\addplot [fill=brown, draw=none, domain=3:1.5] {gauss(0,1.5)} \closedcycle;
\addplot [fill=green, draw=none, domain=4.5:3] {gauss(0,1.5)} \closedcycle;
\addplot [fill=gray, draw=none, domain=6:4.5] {gauss(0,1.5)} \closedcycle;
\addplot [very thick,blue!50!black, domain=-6:6] {gauss(0,1.5)};
% add your labels like this
\node[white,font=\footnotesize] at (axis cs: .8,0.15) {$43.1\%$};
% and this
\node [pin=90:{\footnotesize$0.1\%$}] at (axis cs: -5,0) {};
\end{axis}
\end{tikzpicture}
\end{document}