Filled Histogram
A filled histogram (one with no visible gaps between bars) can be achieved by setting the bar width to the bin size. However, anti-aliasing artifacts may cause white lines to appear between bars. Disable anti-aliasing for each bar to improve appearance of such plots.
ScottPlot.Plot myPlot = new();
// Create a histogram from a collection of values
double[] heights = SampleData.MaleHeights();
var hist = ScottPlot.Statistics.Histogram.WithBinSize(1, heights);
// Display the histogram as a bar plot
var barPlot = myPlot.Add.Bars(hist.Bins, hist.Counts);
// Customize the style of each bar
foreach (var bar in barPlot.Bars)
{
bar.Size = hist.FirstBinSize;
bar.LineWidth = 0;
bar.FillStyle.AntiAlias = false;
}
// Customize plot style
myPlot.Axes.Margins(bottom: 0);
myPlot.YLabel("Number of People");
myPlot.XLabel("Height (cm)");
myPlot.SavePng("demo.png", 400, 300);
This recipe is one of many in the Histogram category
