How can I draw the following graph. I know how to draw a bell curve. But the question is how to draw both curve as shown in the figure. Moreover I want to write $P(X\leq x)=0.7$
Other question is how can I make an animation/gif so the concept become visual.
Here is what I have. But it is far from what I want.
\documentclass[border=5mm]{standalone}
\usepackage{amsmath}
\usepackage{pgfplots}
\DeclareMathOperator{\CDF}{cdf}
\def\cdf(#1)(#2)(#3){0.5*(1+(erf((#1-#2)/(#3*sqrt(2)))))}%
\tikzset{
declare function={
normcdf(\x,\m,\s)=1/(1 + exp(-0.07056*((\x-\m)/\s)^3 - 1.5976*(\x-\m)/\s));
}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
xlabel=$x$,
ylabel=$\CDF(x)$,
grid=major,
legend entries={gnuplot, Bowling et al},
legend pos=south east]
\addplot[smooth, line width=3pt, orange!50] gnuplot{\cdf(x)(0)(2)};
\addplot [smooth, black] {normcdf(x,0,2)};
\end{axis}
\end{tikzpicture}
\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\begin{tikzpicture}
\begin{axis}[every axis plot post/.append style={
mark=none,domain=-2:3,samples=50,smooth}, % All plots: from -2:2, 50 samples, smooth, no marks
axis x line*=bottom, % no box around the plot, only x and y axis
axis y line*=left, % the * suppresses the arrow tips
enlargelimits=upper] % extend the axes a bit to the right and top
\addplot {gauss(0,0.5)};
% \addplot {gauss(1,0.75)};
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
The canonical way to plot something like this is to use the
groupplots
library in order to arrange the plots, and thefillbetween
library for the fills.This can certainly be animated if it is clear which parameter should vary. Assuming you want to vary the horizontal position (
0.7
in the example), you could compile the:and then use
as explained here to get