Cumulative Probability Histogram
A cumulative probability histogram represents the cumulative sum of probabilities or relative frequencies up to each bin, providing a running total of the probability distribution. It is especially useful for evaluating and comparing the distribution of multiple populations.
ScottPlot.Plot myPlot = new();
// Create a histogram from a collection of values
double[][] heightsByGroup = { SampleData.MaleHeights(100), SampleData.FemaleHeights(100) };
string[] groupNames = { "Male", "Female" };
Color[] groupColors = { Colors.Blue, Colors.Red };
for (int i = 0; i < 2; i++)
{
var hist = ScottPlot.Statistics.Histogram.WithBinSize(1, firstBin: 140, lastBin: 200);
hist.AddRange(heightsByGroup[i]);
var curve = myPlot.Add.ScatterLine(hist.Bins, hist.GetCumulativeProbability(100));
curve.LineWidth = 1.5f;
curve.LineColor = groupColors[i];
curve.LegendText = groupNames[i];
curve.ConnectStyle = ConnectStyle.StepVertical;
}
// Customize plot style
myPlot.Legend.Alignment = Alignment.LowerRight;
myPlot.YLabel("Cumulative Probability (%)");
myPlot.XLabel("Height (cm)");
myPlot.SavePng("demo.png", 400, 300);
This recipe is one of many in the Histogram category
