\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{amssymb, amsmath}
\pgfplotsset{compat=1.8}
\begin{document}
\pgfmathdeclarefunction{gauss}{3}{%
\pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}%
}
\begin{tikzpicture}
\begin{axis}[
no markers,
domain=0:6,
samples=100,
ymin=0,
axis lines*=left,
%xlabel=$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,
hide y axis
]
\addplot [very thick,cyan!50!black] {gauss(x, 3, 1)};
\pgfmathsetmacro\valueA{gauss(1,3,1)}
\pgfmathsetmacro\valueB{gauss(2,3,1)}
\draw [gray] (axis cs:3,0) -- (axis cs:3,0.4)
(axis cs:4.2,0) -- (axis cs:4.2,0.19);
\node[below] at (axis cs:4.2, 0) {$1.2$};
\node[below] at (axis cs:3, 0) {$0$};
\end{axis}
\end{tikzpicture}
\end{document}
我想为区间 $0 \leq z \leq 1.2 $ 填充颜色,我该怎么做?
答案1
对于最高版本 1.10,您可以在曲线青色图之前添加以下代码(而不是之后,以实现最佳剪辑):
\addplot[
fill=cyan!50,
draw=none,
domain=3:4.2,
] {gauss(x,3,1)} \closedcycle;
]