ScottPlot.NET
GitHub Repo stars

Filled Error

A line plot with shaded error range may be achieved by layering a FillY beneath a ScatterLine.

ScottPlot.Plot myPlot = new();

// create sample Y values
double[] xs = Generate.Range(0, Math.PI, 0.05);
double[] ys = xs.Select(x => Math.Sin(x) + Generate.RandomNumber(0.1)).ToArray();

// create sample error data
double[] yErr = ys.Select(x => x * Generate.RandomNumber(0.5) + 0.05).ToArray();

// calculate Y ± error
double[] yErrNeg = Enumerable.Range(0, ys.Length).Select(x => ys[x] - yErr[x]).ToArray();
double[] yErrPos = Enumerable.Range(0, ys.Length).Select(x => ys[x] + yErr[x]).ToArray();

// add a shaded area between the error limits
var errFill = myPlot.Add.FillY(xs, yErrNeg, yErrPos);
errFill.LineWidth = 0;
errFill.FillColor = Colors.Blue.WithAlpha(0.2);
errFill.LegendText = "Error";

// add the Y values as a line plot
var meanLine = myPlot.Add.ScatterLine(xs, ys);
meanLine.LineColor = Colors.Blue;
meanLine.LineWidth = 2;
meanLine.LegendText = "Mean";

// configure the location of the legend
myPlot.Legend.Alignment = Alignment.UpperRight;

myPlot.SavePng("demo.png", 400, 300);
This recipe is one of many in the FillY plot category