I am trying to graph a 3D histogram for a dice roll with 3 outcomes. The first set I have either 1, 2, or 3 with the same probabilities. (0.33)

The second time 1, and 2 have 0.25 chance and 3 has 0.5 chance of happening.

I want to make a 3D histogram that shows the probability density of different outcomes. Since 4d plot is not possible one set could be removed (eg. for n3).

Could you please help me with this?

  • $\begingroup$ it is unclear what the plot is supposed to be. What are the plot axes? You make no other mention of n so whats it supposed to mean to "remove" n3 ? $\endgroup$
    – george2079
    Sep 26, 2016 at 15:49

1 Answer 1


To plot the histogram, we need to generate couples describing an event: $(roll 1,roll2)$

An easy way to do this is to use RandomChoice with the appropriate weight. Since both events are independent, we can just generate them separately and merge the two lists together.

With[{n = 1000},
  Transpose[{RandomChoice[{1/3, 1/3, 1/3} -> {1, 2, 3},n], 
    RandomChoice[{0.25, 0.25, 0.5} -> {1, 2, 3},n]}],
  Automatic, "Probability"]

  • 1
    $\begingroup$ note you can give n directly as an argument to RandomChoice instead of using Table $\endgroup$
    – george2079
    Sep 26, 2016 at 15:45
  • $\begingroup$ Good catch! I've edited it in since it improves the readability of the code. $\endgroup$
    – Musang
    Sep 26, 2016 at 16:54

Your Answer

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

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