$Assumptions = (a|b)∈Reals;
setNormal:=(distribution = NormalDistribution[0 , 1];
range = 3;
height = 0.41;
samples = 2000;
w = 0.3;
bNum = 5;
fgp =PDF[distribution];
data = RandomVariate[distribution , samples];);
setTwoNormal:=(distribution = MixtureDistribution[{1 , 1},{NormalDistribution[-1 , 0.2] , NormalDistribution[1 , 0.3]}];
range = 2.5;
height = 1.05;
samples = 2000;
w = 0.1;
bNum = 15;
fgp =PDF[distribution];
data = RandomVariate[distribution , samples];);
setCauchy:=(distribution = CauchyDistribution[0 , 1];
range = 3;
height = 0.35;
samples = 2000;
w = 0.3;
bNum = 5;
fgp =PDF[distribution];
data = RandomVariate[distribution , samples];);
setNormal;
setDist["normal 1"]:=setNormal;
setDist["normal 2"]:=setTwoNormal;
setDist["cauchy"]:=setCauchy;
Manipulate[Module[{dat , in , h , ex , varx},
setDist[dist];
dat=data[[1;;d]];
in = Cases[dat , x_/; n w≤x < (n + 1)w];
h = If[d == 0 , 0,((Dimensions[in][[1]])/(d w))];
ex = If[d == 0 , 0,Mean[dat]];
varx = If[d <= 2 , 0,Variance[dat]];
Show[Graphics[{{Black ,Arrow[{{ex-(Sqrt[varx]) , 0 height} , {ex+(Sqrt[varx]) , 0 height}}],Arrow[{{ex+(Sqrt[varx]) , 0 height} , {ex-(Sqrt[varx]) , 0 height}}] , Text["(Sqrt[(σ^2) (x)])" , {ex , 0.05} , {0 , -1}] ,Line[{{ex , 0.05 height},{ex , 0.0}}]},{Red , Opacity[0.8],Rectangle[{n w , 0} , {(n + 1) w , h}]}}],Plot[fgp[u] , {u , -range , range} , PlotStyle->Thick],PlotRange->{{-range , range} , {0 , height}},AxesLabel->{"u" , None},GridLines->{data[[1;;d]] , None} , Frame->True , AspectRatio->1/2 ]] , {{dist , "normal 1", "distribution"} , {"normal 1" , "normal 2", "cauchy"}},{{d , 0 , "samples"} , 0 , samples , 1} , {{n , 0 , "bin number"} , -bNum , bNum , 1}]