1
$\begingroup$

How can I plot a 3D graph that shows how a histogram varies with a particular parameter?

A simple example of this would be plotting a histogram of data described by a gaussian. The gaussian is of unit height and centered on the origin so that the only parameters are x and a, where a describes the width of the gaussian.

Gaussian=Exp[-x^2/(2*a^2)]

I can then plot of histogram of the data for a given value of a. For example,

Gaussian1=Gaussian/.a->1
Table=[Gaussian1,{x,-20,20}]
Histogram[Table]

However what I want to show is how this histogram will change as a is varied. So what will be produced is a 3D graph, with the z axis as the bin count, x axis as x, and y axis as a. We should then see the histogram narrow as a increases, i.e. along along the y axis.

My actual code looks at the dispersion of electrons in a varying electric field. A histogram can be produced that shows the trajectories of electrons at any given time relative to a chosen direction, however I want to show how this dispersion changes with time, since the electric field itself is time varying.

Thanks in advance.

$\endgroup$
2
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$
    – bbgodfrey
    Jan 19, 2015 at 18:18
  • $\begingroup$ Please provide a simplified example of the code that is not working as you desire. Otherwise, your question is difficult to address. $\endgroup$
    – bbgodfrey
    Jan 19, 2015 at 18:20

1 Answer 1

1
$\begingroup$
mydata = Table[
   {σ, RandomVariate[NormalDistribution[0, σ]]},
   {σ, 1, 10, .5}, {100}];

Histogram3D[mydata,
 AxesLabel -> Text[Style[#, Italic, 14]] & /@ {"σ", "x", "Count"}]

enter image description here

A prettier version, with the Gaussians superimposed:

mydata = Table[
   {σ, RandomVariate[NormalDistribution[0, σ]]},
   {σ, 1, 10}, {100}];

Show[
 Histogram3D[
  mydata,
  PlotRange -> {{0, 10}, {-20, 20}, {0, All}},
  AxesLabel -> (Text[Style[#, Italic, 14]] & /@ {"σ", "x", "Count"})],

ParametricPlot3D[
   Evaluate[
    Table[
     {σ + .5, x, 200 PDF[NormalDistribution[0, σ], x]},
     {σ, 1, 10, 1}]], {x, -20, 20},
   PlotRange -> {{-20, 20}, {0, 10}, {0, All}},
   PlotStyle -> Thick,
   BoxRatios -> {1, 1, 1}
   ]
 ]

enter image description here

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.