# How to do a parametric histogram?

Is it possible to draw a spectral histogram from two random sets ? More specifically, I have these two random functions (fmin, fmax and Nwaves would be variables in a Manipulate box) :

fmin = 0;
fmax = 4;

Amplitude[k_] := Amplitude[k] = If[k == 0, 1, RandomReal[{0.5, 1}]]
Frequency[k_, fmin_, fmax_] := Frequency[k, fmin, fmax] = If[k == 0, 1, RandomReal[{fmin, fmax}]]


where k is an integer variable going from k = 0 up to k = Nwaves. Lets take Nwaves = 50. I would like to plot the random frequencies on an horizontal axis, and their random amplitude on the vertical axis to define a spectral plot.

How can we do this plot in Mathematica ? Please, note that I'm using Mathematica version 7.

EDIT : This is almost a solution, but it's not exactly like an "histogram" (with thin vertical bars) :

Clear["Global*"]

fmin = 0;
fmax = 4;

Amplitude[k_] := Amplitude[k] = If[k == 0, 1, RandomReal[{0.5, 1}]]
Frequency[k_, fmin_, fmax_] := Frequency[k, fmin, fmax] = If[k == 0, 1, RandomReal[{fmin, fmax}]]

ListPlot[
Table[{Frequency[k, fmin, fmax], Amplitude[k]}, {k, 0, 50}],
PlotRange -> {{0, 5}, {0, 1}},
PlotStyle -> {Blue, AbsolutePointSize},
AspectRatio -> 1,
Frame -> True,
ImageSize -> 500
] • If you only have Mathematica 7, please mention this in the question. – Szabolcs Mar 31 '16 at 13:07

Perhaps you would like to use Histogram3D

Manipulate[
Histogram3D[
Table[{Frequency[k, r, fmin, fmax], Amplitude[k, r]}, {k, 0, Nwaves - 1}]],
{{Nwaves, 1, Style["Number of waves", 10]}, 1, 50, 1, ImageSize -> Large,
Appearance -> {"Labeled", "Closed"}}, {{fmin, 0,
Style["Min frequency", 10]}, 0, fmax, 0.001, ImageSize -> Large,
Appearance -> {"Labeled", "Closed"}}, {{fmax, 4,
Style["Max frequency", 10]}, 0, 4, 0.01, ImageSize -> Large,
Appearance -> {"Labeled", "Closed"}}, Delimiter,
Button[Style["Randomize", Bold, Red, 12], {r = RandomReal[]},
Appearance -> "Palette", ImageSize -> {100, 24}],
ControlPlacement -> Bottom, FrameMargins -> None] While not an histogram, this Manipulate is mostly fun !

Clear["Global*"]

r = 1;

Amplitude[k_, r_] := Amplitude[k, r] = If[k == 0, 1, RandomReal[{0.5, 1}]]
Frequency[k_, r_, fmin_, fmax_] := Frequency[k, r, fmin, fmax] = If[k == 0, 1, RandomReal[{fmin, fmax}]]

Manipulate[
ListPlot[
Table[{Frequency[k, r, fmin, fmax], Amplitude[k, r]}, {k, 0, Nwaves - 1}],
PlotRange -> {{0, 5}, {0, 1}},
PlotStyle -> {Blue, AbsolutePointSize},
AspectRatio -> 1,
Frame -> True,
ImageSize -> 400
],
{{Nwaves, 1, Style["Number of waves", 10]},
1, 50, 1, ImageSize -> Large,
Appearance -> {"Labeled", "Closed"}},
{{fmin, 0, Style["Min frequency", 10]},
0, fmax, 0.001, ImageSize -> Large,
Appearance -> {"Labeled", "Closed"}},
{{fmax, 4, Style["Max frequency", 10]},
0, 4, 0.01, ImageSize -> Large,
Appearance -> {"Labeled", "Closed"}},
Delimiter,
Button[
Style["Randomize", Bold, Red, 12],
{r = RandomReal[]}, Appearance -> "Palette",
ImageSize -> {100, 24}
],
ControlPlacement -> Bottom,
FrameMargins -> None
] 