1

enter image description here

\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}

I want to fill color the interval $0 \leq z \leq 1.2 $, how can I do that?

Rinzler
  • 13
  • Welcome to TeX.SX! Does this help? http://tex.stackexchange.com/a/165666/32374 – darthbith May 16 '15 at 13:15
  • 2
    I think this is a duplicate of http://tex.stackexchange.com/questions/83503/fill-the-area-determined-by-two-pgfplots-graphs . Would you agree? – percusse May 16 '15 at 13:52
  • No, it is not duplicate. I want to get a simpler answer. [link] (http://tex.stackexchange.com/questions/83503/fill-the-area-determined-by-two-pgfplots-graphs) here, they metioned about intersection of two curves. This question is different. @percusse – Rinzler May 16 '15 at 14:09
  • I see but you can intersect the curve with the verticals for that purpose no? That's what the answer of Christian does. But in anycase you can draw the curve twice, once full domain and once filled but limited domain on top. – percusse May 16 '15 at 14:11
  • You are absolutely right. However, my LateX skill isn't enough to adapt the answer of Christian to my LateX source. @percusse – Rinzler May 16 '15 at 14:17
  • @percusse Christian's answer is for version 1.10, but this question uses 1.8, so he'll have to use Jake's answer I suppose. – Alenanno May 16 '15 at 15:00

1 Answers1

1

For up to the version 1.10, you can add the following code just before your curve cyan plot (not after, for optimal clipping):

\addplot[
    fill=cyan!50,
    draw=none,
    domain=3:4.2,
    ] {gauss(x,3,1)} \closedcycle;
]

enter image description here

Alenanno
  • 37,338