Stacked Range Chart
Stacked range charts depict multiple ranges for a discrete set of items
ScottPlot.Plot myPlot = new();
// prepare a custom color palette
string[] colorCodes = ["#3369cc", "#95bce3", "#f4a861", "#fd8d00"];
ScottPlot.Palettes.Custom palette = new(colorCodes);
// create a stacked bar chart with a collection of named ranges
string[] rangeNames = ["Yearly Low", "Mean Daily Low", "Mean Daily High", "Yearly High"];
List<(string name, double[] edges)> ranges =
[
("Ontario", [-9, 3, 7, 13, 27]),
("England", [4, 7, 12, 16, 24]),
("Kentucky", [-4, 7, 13, 20, 30]),
];
myPlot.Add.StackedRanges(ranges, palette);
// use tick labels with a degree symbol
ScottPlot.TickGenerators.NumericAutomatic tickGen = new();
myPlot.Axes.Left.TickGenerator = tickGen;
tickGen.LabelFormatter = (x) => $"{x}º";
// display the legend outside the data area
myPlot.ShowLegend(Edge.Right);
// add items to the legend manually
for (int i = 0; i < rangeNames.Length; i++)
{
LegendItem item = new()
{
LabelText = rangeNames[i],
FillColor = palette.GetColor(i),
};
myPlot.Legend.ManualItems.Add(item);
}
myPlot.Legend.ManualItems.Reverse();
// improve styling and alignment
myPlot.Legend.OutlineStyle.IsVisible = false;
myPlot.Legend.ShadowColor = Colors.Transparent;
myPlot.Legend.Padding = new(0);
myPlot.Axes.Right.MaximumSize = 0;
myPlot.SavePng("demo.png", 400, 300);
This recipe is one of many in the Bar Plot category
