Skip to main content
2 of 4
Formatted code, added plotting tag, since the problem is really in the plotting and not in the calculation
MarcoB
  • 67.7k
  • 18
  • 96
  • 198

Gaps in CDF produced from HistogramDistribution

I have about 200 real numbers spread over the range 0-400. I use HistogramDistribution to bin them and PDF to create the resulting step-wise probability distribution. I assumed that CDF applied to the HistogramDistribution would yield a continuous, piece-wise linear function, but I keep getting these annoying gaps in the CDF. Here's the code I'm using applied to some random data:

data = Table[400*RandomReal[], {200}];
pd = PDF[HistogramDistribution[data, 20]];
Plot[pd[x], {x, 0, 400}]
Plot[CDF[HistogramDistribution[data, 20], x], {x, 0, 400}]

Any idea what's causing the gaps and how to get rid of them?