Filling smoothed histogram with area representing standard deviation?

s = ColorData[1];
d = Table[RandomVariate[NormalDistribution[c, 2], 500], {c, 0, 9, 3}];
(*filling Mean ± Std Dev.You may chose other limits*)
lims = MapThread[({#1 - #2, #1 + #2}) &, {Mean /@ d, StandardDeviation /@ d}];

dd = Transpose[{d, lims}];
i = 1;
f[x_] := GeometricTransformation[Rotate[x, -Pi/2, {0, 0}], ReflectionTransform[{0, 1}]]

sHV = Show[{SmoothHistogram[#[[1]], PlotStyle-> s@i, PlotRange-> {{-6, 15}, Automatic}], 
            SmoothHistogram[#[[1]], PlotStyle-> s@i, Filling -> Axis, 
                        RegionFunction -> Function[{x, y}, #[[2, 1]] < x < #[[2, 2]]], 
                        FillingStyle -> Directive[Opacity[.2], s[i++]]]} & /@ dd];


Show[sHV/. x_Polygon | x_Line:> f@x, 
     PlotRange -> Reverse[PlotRange /. AbsoluteOptions[sHV, PlotRange]],
     AspectRatio-> 2]

Mathematica graphics


Define a function using a combination of the options Mesh, MeshShading and ColorFunction to get partially filled histograms:

shF = SmoothHistogram[#, Filling -> Axis, 
  Mesh -> {#2}, MeshStyle -> Transparent, MeshShading -> {#3, Directive[Thick,#3]}, 
  ColorFunctionScaling -> False,
  ColorFunction->Function[{x, y}, If[#2[[1]]<=x<=#2[[2]], Opacity[.4, #3], Transparent]]]&;

and a function to flip the axes by post-processing to reverse the elements in the first argument of GraphicsComplex:

flipF = # /.  GraphicsComplex[p_, x__] :> GraphicsComplex[Reverse /@ p, x] &;

Using an input setup similar to belisarius's:

d = Table[RandomVariate[NormalDistribution[c, 2], 500], {c, 0, 6, 2}];
lims =({#1 - #2, #1 + #2}) & @@@ Thread[{Mean /@ d, StandardDeviation /@ d}];
colors = ColorData[1, "ColorList"][[;; 4]];
ddd = Transpose[{d, lims, colors}];


Show[flipF@Show[shF @@@ ddd], AspectRatio -> 2, PlotRange -> All]

Mathematica graphics

Tags:

Plotting