OscillatorPlot::usage = ""

Begin["Private`"]

OscillatorFunction[n_,x_] :=
   HermiteH[n,x]*Exp[-x^2/2]/Sqrt[2^n*n!]/Pi^(1/4)

OscillatorPlot[f_, {x_Symbol, x1_: - Infinity, x2_:Infinity},
    n1_:0, n2_:10] := 
  Module[{coeff, coloredLine, lineTable, up, upper, 
    lower, func},
    func = Function[{x}, f]; 
    Do[coeff[n] = NIntegrate[OscillatorFunction[n, x]*
        func[x], {x, x1, x2}], {n, n1, n2}]; 
    coloredLine[n_] := {Thickness[0.01], 
      Hue[Arg[coeff[n]]/(2*Pi)], 
      Line[{{n + 1/2, Abs[coeff[n]]}, 
        {n + 1/2, 0.}}]};
    lineTable = 
     Graphics[Table[coloredLine[n], {n, n1, n2}]]; 
    up = Max[Table[Abs[coeff[n]], {n, n1, n2}]]; 
    upper = up + up/10; lower = -(up/10); 
    Show[lineTable, Frame -> True,
        PlotRange -> {{n1, n2 + 1}, {lower, upper}}]]

End[]
