# What is a good way to display many discrete probability distributions on the same plot in Mathematica?

For something like 2 to 30 distributions each with 2 to 30 values.

If we assume the distributions have unique values, a standard stacked bar chart is insufficient, but maybe something similar would be good? Unique values in the distributions means that not only do they have different probabilities, but their possible values are over the reals and are different in each distribution.

So, for example, if I were trying to represent the proportion of horses of various colors in different geographic regions(latitudes), then the standard stacked bar chart would work, one distribution for each region. But, if I were trying to represent various lotteries which each have their own system of payouts with various probabilities, then the chart would not be sufficient, because the payouts would be in the reals, and they wouldn't necessarily fall into neat categories like brown, black, white, grey. See my hack, each outcome has a different value in addition to its probability.

If color is used to display the value of each possibility within the discrete probability distribution, each probability could be represented by the height of the bar region, and each region could be vertically ordered by value.

So, check out this hack I made of a DensityPlot using piecewise functions to demonstrate the idea; there must be a better solution in Mathematica.

valseg[n_] := {Sort[RandomReal[1, n]], Sort[RandomReal[1, n - 1]]};
piece[{vals_, segs_}] :=
Piecewise[
Prepend[Append[
Table[{vals[[i + 1]], segs[[i]] < y < segs[[i + 1]]}, {i,
Length[segs] - 1}], {vals[[1]],
y < segs[[1]]}], {vals[[Length[vals]]],
y > segs[[Length[segs]]]}]];
piecefunc1 = piece[valseg[5]];
piecefunc2 = piece[valseg[5]];
d1 = DensityPlot[piecefunc1, {x, 0, 1}, {y, 0, 1},
ColorFunction -> "ThermometerColors" ];
d2 = DensityPlot[piecefunc2, {x, 1, 2}, {y, 0, 1} ,
ColorFunction -> "ThermometerColors"];
Show[d1, d2, PlotRange -> {{0, 2}, {0, 1}}]


There is another example given with sample values: Distribution 1: 50% chance of getting a 10.4, 50% chance of getting a 20.5 Distribution 2: 80% chance of getting a 50.6, 20% chance of getting a 5.5. Distribution 3: 10% chance each for getting 5.1, 10.2, 15.3, 20.4, 15.5, 20.6, 25.7, 30.8, 35.9, 40. For the hack, it looks like this:

• This is an interesting question but I don't see how it quite fits as a Mathematica question. You might consider posting this on Cross Validated. But in any event...what characteristics do you want the reader to see with such a display? Variability in proportions? Changes over time or some other variable that ties all of the 30 distributions together?
– JimB
Commented Sep 10, 2015 at 22:03
• "a standard stacked bar chart is insufficient," Insufficient for what purpose? In what sense? Commented Sep 10, 2015 at 22:11
• I want the reader to see it as a landscape from which they can intuit a sense of the overall cumulative density through the sequence progression without losing information about individual contributions to the sequence. It could represent a change over time, yes. Commented Sep 10, 2015 at 22:36
• Sorry, I stopped understanding beginning with the word "landscape." You might want to consider an arrangement of multivariate glyphs. See page 6 at researchgate.net/publication/….
– JimB
Commented Sep 10, 2015 at 22:47
• Thanks for the link! I think I would have to use glyphs if I wanted to represent anything more than this on one plot. Commented Sep 10, 2015 at 22:56

For the example given:

• Distribution 1: 50% chance of getting a 10.4, 50% chance of getting a 20.5
• Distribution 2: 80% chance of getting a 50.6, 20% chance of getting a 5.5.
• Distribution 3: 10% chance each for getting 5.1, 10.2, 15.3, 20.4, 15.5, 20.6, 25.7, 30.8, 35.9, 40

Histogram3D[ {{{1, 10.4}, {1, 20.6}}, {{2, 50.6}, {2, 50.6}, {2, 50.6}, {2, 50.6}, {2, 5.5}}, {{3, 5.1}, {3, 10.2}, {3, 15.3}, {3, 20.4}, {3, 20.6}, {3, 25.7}, {3, 30.8}, {3, 35.9}, {3, 40}}}, {3, 10}, "Probability", AxesLabel -> {Text[Style["Distribution index", 18]], Text[Style["Value", 18]], Text[Style["Probability", 18]]}, ImageSize -> 700]

Alternatively:

    ListPointPlot3D[{
{{1, 10.4, .5}, {1, 20.6, .5}},
{{2, 50.6, .8}, {2, 5.5, .2}},
{{3, 5.1, .1}, {3, 10.2, .1}, {3, 15.3, .1}, {3, 20.4, .1},
{3, 20.6, .1}, {3, 25.7, .1}, {3, 30.8, .1}, {3, 35.9, .1},
{3, 40, .1}}},
Filling -> Bottom,
PlotRange -> {0, 1},
PlotStyle -> {{PointSize[0.02], Red}, {PointSize[0.02],
Green}, {PointSize[0.02], Blue}},
FillingStyle -> Thick,
Ticks -> {{1, 2, 3}, Automatic, Automatic},
AxesLabel -> {
Text[Style["Distribution index", 16]],
Text[Style["Value", 16]],
Text[Style["Probability", 16]]},
ImageSize -> 500]


• Yes, this represents the data sufficiently! Thank you. I believe a 2D representation would still be useful to be able to plot in the case of a large number of distributions and/or a large number of possibilities per distribution. Commented Sep 11, 2015 at 0:28
• Awwh, man. I spent too much time checking out options on ListPointPlot3D and you beat me too it. LOL Commented Sep 11, 2015 at 1:03

Perhaps

BarChart[RandomReal[1, {5, 5}], ChartLayout -> "Percentile", Joined -> True]


• Ohh, pretty! +1
– ciao
Commented Sep 10, 2015 at 22:19
• It is nice but it only represents discrete probability functions which have identical outcome values. This is like 1D when I need 2D, because the bars don't contain value data; they are the same 5 colors for each, as if they are categories. Commented Sep 10, 2015 at 22:45
• I find the original question itself confusing. What does "assume the distributions have unique values" mean? Consider two Gaussian distributions with vastly different means and standard deviations, do those have "unique values"? Please give full information (actual numbers, etc.) for two representative distributions you seek to display on the same graph. Commented Sep 10, 2015 at 23:18
• Distribution 1: 50% chance of getting a 10.4, 50% chance of getting a 20.5. Distribution 2: 80% chance of getting a 50.6, 20% chance of getting a 5.5. Distribution 3: 10% chance each for getting 5.1, 10.2, 15.3, 20.4, 15.5, 20.6, 25.7, 30.8, 35.9, 40. Commented Sep 10, 2015 at 23:28

If you have the discrete probabilities in $\{value,prob\}$ pairs.

dist1 = {{10.4, .5}, {20.5, .5}};
dist2 = {{50.6, .8}, {5.5, .2}};
dist3 = {#, .1} & /@ {5.1, 10.2, 15.3, 20.4, 15.5, 20.6, 25.7, 30.8, 35.9, 40.};


Then a ListPlot could be used to plot the PDF.

ListPlot[{dist1, dist2, dist3}, Filling -> Axis,
PlotMarkers ->
Graphics[{EdgeForm[{Thin, Black}], Opacity[.65], Disk[{0, 0}, Scaled[.03]]}],
FillingStyle -> Medium]


Update

For many distributions a ListPointPlot3D can be used.

ListPointPlot3D[
MapIndexed[
Function[{item, index}, {First@index, Sequence @@ #} & /@ item],
{dist1, dist2, dist3, dist1, dist2, dist3}, 1],
Filling -> Bottom,
PlotRange -> Full,
PlotStyle -> Directive[PointSize[Large], Opacity[.7]],
FaceGrids -> {{{-1, 0, 0}, {None, Automatic}}, {{0, 1, 0}, {None,
Automatic}}},
FaceGridsStyle -> Directive[LightGray],
Boxed -> False,
AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}}]


A BubbleChart would work. It is 2D but it displays 3D data. There is no overlap of the distributions. The LabelingFunction has been updated to show the probabilities.

BubbleChart[
MapIndexed[
Function[{item, index}, {First@index, Sequence @@ #} & /@ item],
{dist1, dist2, dist3, dist1, dist2, dist3}, 1],
ChartBaseStyle ->
Directive[EdgeForm[{Black, Thin, Opacity[1]}], Opacity[0.5]],
FrameTicks ->
{
{Automatic, Automatic},
{{#, StringTemplate["\!$$\*SubscriptBox[\(X$$, $$1$$]\)"][#]} & /@ Range[6], Automatic}
},
LabelingFunction ->
Function[{value, index, lbls},
StringTemplate[
"\[DoubleStruckCapitalP]( \!$$\*SubscriptBox[\(X$$, $$1$$]\) = 2) = 3"][First@index, value[[2]], value[[3]]]]]


• Yes, this does fully represent the data. But imagine many distributions with many possibilities - then this display becomes very crowded and difficult to gain intuition. Commented Sep 11, 2015 at 0:32
• See update but David beat me too it as I was checking out options to make it look a little prettier. Commented Sep 11, 2015 at 1:04
• Thank you, Edmund. I am still seeking a 2D solution as in my hack, though. Commented Sep 11, 2015 at 1:29
• See update for BubbleChart. Also add option ChartBaseStyle -> Directive[EdgeForm[{Black, Thick}], Opacity[0.3]] to notice over-printing in a distribution. Like in 3 and 6 in the example. Commented Sep 11, 2015 at 10:38