Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I often find myself trying to plot multiple PDFs for my courses. I find the default tools available to me are lacking and/or cumbersome. After readings some suggestions here, I have come up with the following code to plot 3 instances of the Binomial Distribution. I'm hoping this will prove useful to others (perhaps even myself). I'm also wondering if folks can improve on this.

n = 12;
plist = {1/6, 1/3, 2/3};
colorList = {Magenta, Blue, Green};
  Map[PDF[BinomialDistribution[n, #], Floor[k]] &, 
   plist]], {k, -0.001, n + 0.001},
 Exclusions -> None,
 PlotStyle -> Map[{Thick, #} &, colorList],
 PlotLegends -> plist,
 Frame -> {True, True, False, False},
 FrameTicks -> {Table[i, {i, 0 , n, 2}], Automatic},
 FrameLabel -> {"Successes k", "Probability"}]

Here's the output plot of multiple histograms

share|improve this question
For example, can you comment on what you don't like about your solution? – bobthechemist Jan 20 '14 at 19:53
In my opinion there is a problem with this plot, in that the steps occur at integer values on the k axis. e.g. the value of the magenta curve at k=1 is both 0.12 and 0.27. Unless you know the code that was used to create the plot, there is no way to tell which is the correct value. – Simon Woods Jan 20 '14 at 20:12
Seen DiscretePlot ? – Sjoerd C. de Vries Jan 20 '14 at 21:54
@SjoerdC.deVries I tried using DiscretePlot, but I couldn't figure out an elegant way to get the lines the way I wanted instead of simple markers as is the default. – mikemtnbikes Jan 20 '14 at 22:09
I agree with @SimonWoods that the location of the bin boundaries are ambiguous. It seems like this could be solved by replacing "k" in "Floor[k]" with "Floor[k+1/2]" and changing the lower bound of the range of k from "-0.001" to "-0.5001" – mikemtnbikes Jan 20 '14 at 22:13

Here's my quick and dirty take on it using DiscretePlot. (As also suggested by Sjoerd in the comments above.) Playing around with ExtentSize and ExtentMarkers can give you a variety of choices for how the lines are displayed.

I'm not sure what constitutes "better" from your perspective, but the following code generates something similar to your solution:

  {PDF[BinomialDistribution[12, 1/6], x], 
   PDF[BinomialDistribution[12, 1/3], x], 
   PDF[BinomialDistribution[12, 2/3], x]}, {x, 0, 12}, 
   ExtentSize -> Right,                            (* Lines extend to the right *)
   ExtentMarkers -> {Point, Null},                 (* Markers to resolve the ambiguity *)
   Frame -> True, 
   PlotRange -> {{-0.25, 13.25}, {-0.01, 0.32}},   (* Set "handraulically", could be automated *)
   BaseStyle -> {FontSize -> 12}, 
   FrameLabel -> {Style["Number of successes (k)", 16], 
      Style["Probability", 16]}, 
   PlotStyle -> Directive[AbsoluteThickness[2], AbsolutePointSize[6]], 
   ImageSize -> 625

The plot, in all its "glory":

enter image description here

Note that I have not included a legend for the plot as you have. In my production work (final figures for journal articles or internal tech reports), I tend to do plot legends or other labelling either via Epilog and direct graphics commands, or by post-editing in Adobe Illustrator, depending on the complexity of the desired annotations/markup. Not necessarily the most optimal workflow, but it gives me the greatest fine-grained control over the output.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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