I have the following function that plots an error bar.
public void AddErrorBarsTwoSigma(string curveName, List<double> xValues, List<double> yValues, List<double> yErrors, Color color)
{
if (xValues.Count != yValues.Count || yValues.Count != yErrors.Count)
{
throw new ArgumentException("All lists must be of equal length.");
}
ErrorBarItem errorBar = myPane_.AddErrorBar(curveName, xValues.ToArray(), yValues.ToArray(), yErrors.ToArray(), color);
errorBar.Bar.IsVisible = true;
errorBar.Bar.PenWidth = DefaultLineWidth;
errorBar.Bar.Color = color;
// Refresh the graph to show changes
zgc_.AxisChange();
zgc_.Invalidate();
}
The gray line is the error curve.
I want to modify this function so that it draws error bars one sigma up and one sigma down.
How can I do that?
Drive program looks like the following:
using System;
using System.Collections.Generic;
using System.Drawing;
using WeightedLinearRegressionNamespace;
using ZedGraph;
public class WeightedLinearRegression
{
public static void Main(string[] args)
{
// Create a new ZedGraphControl
ZedGraphControl zgc = new ZedGraphControl();
zgc.Size = new Size(1200, 800);
// Sample data points and their corresponding errors
double[] xData = new double[] { 1, 2, 3, 4, 5 };
double[] yData = new double[] { 2, 4, 6, 8, 10 };
double[] yErrors = new double[] { 0.5, 0.8, 0.6, 0.9, 0.7 };
ZedGraphPlotter plotter = new ZedGraphPlotter(zgc);
plotter.AddErrorBarsTwoSigma("bars",
new List<double>(xData),
new List<double>(yData),
new List<double>(yErrors),
Color.Red);
plotter.AddCurve("errors", new List<double>(yErrors));
plotter.SavePlot("", "error_bar_with_2_sigma.png");
}
}
