Stacked Bar Plot
Bars can be positioned on top of each other.
ScottPlot.Plot myPlot = new();
ScottPlot.Palettes.Category10 palette = new();
ScottPlot.Bar[] bars =
{
// first set of stacked bars
new() { Position = 1, ValueBase = 0, Value = 2, FillColor = palette.GetColor(0) },
new() { Position = 1, ValueBase = 2, Value = 5, FillColor = palette.GetColor(1) },
new() { Position = 1, ValueBase = 5, Value = 10, FillColor = palette.GetColor(2) },
// second set of stacked bars
new() { Position = 2, ValueBase = 0, Value = 4, FillColor = palette.GetColor(0) },
new() { Position = 2, ValueBase = 4, Value = 7, FillColor = palette.GetColor(1) },
new() { Position = 2, ValueBase = 7, Value = 10, FillColor = palette.GetColor(2) },
};
myPlot.Add.Bars(bars);
Tick[] ticks =
{
new(1, "Spring"),
new(2, "Summer"),
};
myPlot.Axes.Bottom.TickGenerator = new ScottPlot.TickGenerators.NumericManual(ticks);
myPlot.Axes.Bottom.MajorTickStyle.Length = 0;
myPlot.HideGrid();
// tell the plot to autoscale with no padding beneath the bars
myPlot.Axes.Margins(bottom: 0);
myPlot.SavePng("demo.png", 400, 300);
This recipe is one of many in the Bar Plot category
