public void ExecuteRecipe(Plot plt) { var bar1 = plt.AddBar(new double[] { 10, 13, 15 }, new double[] { 1, 5, 9 }); bar1.HatchStyle = Drawing.HatchStyle.StripedUpwardDiagonal; bar1.FillColor = Color.Gray; bar1.FillColorHatch = Color.Black; bar1.Label = "Series 1"; var bar2 = plt.AddBar(new double[] { 14, 15, 9 }, new double[] { 2, 6, 10 }); bar2.HatchStyle = Drawing.HatchStyle.StripedWideDownwardDiagonal; bar2.FillColor = Color.DodgerBlue; bar2.FillColorHatch = Color.DeepSkyBlue; bar2.Label = "Series 2"; var bar3 = plt.AddBar(new double[] { 13, 6, 14 }, new double[] { 3, 7, 11 }); bar3.HatchStyle = Drawing.HatchStyle.LargeCheckerBoard; bar3.FillColor = Color.SeaGreen; bar3.FillColorHatch = Color.DarkSeaGreen; bar3.Label = "Series 3"; // add a legend to display each labeled bar plot plt.Legend(location: Alignment.UpperRight); // adjust axis limits so there is no padding below the bar graph plt.SetAxisLimits(yMin: 0, yMax: 20); }
public void ExecuteRecipe(Plot plt) { // male and female heights are based on https://ourworldindata.org/human-height Random rand = new(0); double[] heightsMale = ScottPlot.DataGen.RandomNormal(rand, pointCount: 2345, mean: 178.4, stdDev: 7.6); double[] heightsFemale = ScottPlot.DataGen.RandomNormal(rand, pointCount: 1234, mean: 164.7, stdDev: 7.1); // calculate histograms for male and female datasets (double[] probMale, double[] binEdges) = ScottPlot.Statistics.Common.Histogram(heightsMale, min: 140, max: 210, binSize: 1, density: true); (double[] probFemale, _) = ScottPlot.Statistics.Common.Histogram(heightsFemale, min: 140, max: 210, binSize: 1, density: true); double[] leftEdges = binEdges.Take(binEdges.Length - 1).ToArray(); // convert probabilities to percents probMale = probMale.Select(x => x * 100).ToArray(); probFemale = probFemale.Select(x => x * 100).ToArray(); // plot histograms var barMale = plt.AddBar(values: probMale, positions: leftEdges); barMale.BarWidth = 1; barMale.FillColor = Color.FromArgb(50, Color.Blue); barMale.BorderLineWidth = 0; var barFemale = plt.AddBar(values: probFemale, positions: leftEdges); barFemale.BarWidth = 1; barFemale.FillColor = Color.FromArgb(50, Color.Red); barFemale.BorderLineWidth = 0; // plot probability function curves double[] pdfMale = ScottPlot.Statistics.Common.ProbabilityDensity(heightsMale, binEdges, percent: true); plt.AddScatterLines( xs: binEdges, ys: pdfMale, color: Color.FromArgb(150, Color.Blue), lineWidth: 3, label: $"Male (n={heightsMale.Length:N0})"); double[] pdfFemale = ScottPlot.Statistics.Common.ProbabilityDensity(heightsFemale, binEdges, percent: true); plt.AddScatterLines( xs: binEdges, ys: pdfFemale, color: Color.FromArgb(150, Color.Red), lineWidth: 3, label: $"Female (n={heightsFemale.Length:N0})"); // customize styling plt.Title("Human Height by Sex"); plt.YLabel("Probability (%)"); plt.XLabel("Height (cm)"); plt.Legend(location: ScottPlot.Alignment.UpperLeft); plt.SetAxisLimits(yMin: 0); }
public void ExecuteRecipe(Plot plt) { // let's plot 24 hours of data int pointCount = 24; // generate some random values var rand = new Random(0); double[] values = DataGen.Random(rand, pointCount, 1, 2); // space every time point by 1 hour from a starting point DateTime start = new DateTime(2021, 09, 24, 0, 0, 0); double[] positions = new double[pointCount]; for (int i = 0; i < pointCount; i++) { positions[i] = start.AddHours(i).ToOADate(); } // display the bar plot using a time axis var bar = plt.AddBar(values, positions); plt.XAxis.DateTimeFormat(true); // indicate each bar width should be 1/24 of a day then shrink sligtly to add spacing between bars bar.BarWidth = (1.0 / 24) * .8; // adjust axis limits so there is no padding below the bar graph plt.SetAxisLimits(yMin: 0); }
public void ExecuteRecipe(Plot plt) { // generate sample heights are based on https://ourworldindata.org/human-height Random rand = new(0); double[] heights = ScottPlot.DataGen.RandomNormal(rand, pointCount: 1234, mean: 178.4, stdDev: 7.6); // create a histogram var hist = new ScottPlot.Statistics.Histogram(heights, min: 140, max: 220, binSize: 1); // display histogram probabability as a bar plot var bar = plt.AddBar(values: hist.countsFrac, positions: hist.bins); bar.FillColor = ColorTranslator.FromHtml("#9bc3eb"); bar.BorderColor = ColorTranslator.FromHtml("#82add9"); bar.BarWidth = hist.binSize; // display histogram distribution curve as a line plot plt.AddScatterLines( xs: hist.bins, ys: hist.probability, color: Color.Black, lineWidth: 2, lineStyle: LineStyle.Dash); // customize the plot style plt.Title("Adult Male Height"); plt.YAxis.Label("Probability"); plt.XAxis.Label("Height (cm)"); plt.SetAxisLimits(yMin: 0); }
public void ExecuteRecipe(Plot plt) { Random rand = new Random(0); double[] values = DataGen.RandomNormal(rand, pointCount: 1000, mean: 50, stdDev: 20); var hist = new ScottPlot.Statistics.Histogram(values, min: 0, max: 100); // plot the bins as a bar graph (on the primary Y axis) var bar = plt.AddBar(hist.counts, hist.bins); bar.BarWidth = hist.binSize * 1.2; // oversize to reduce render artifacts bar.BorderLineWidth = 0; bar.YAxisIndex = 0; plt.YAxis.Label("Count (#)"); plt.YAxis.Color(bar.FillColor); // plot the mean curve as a scatter plot (on the secondary Y axis) var sp = plt.AddScatter(hist.bins, hist.countsFracCurve); sp.MarkerSize = 0; sp.LineWidth = 2; sp.YAxisIndex = 1; plt.YAxis2.Label("Fraction"); plt.YAxis2.Color(sp.Color); plt.YAxis2.Ticks(true); // decorate the plot plt.XAxis2.Label("Normal Random Data", bold: true); plt.XAxis.Label("Value (units)"); plt.SetAxisLimits(yMin: 0); plt.Grid(lineStyle: LineStyle.Dot); }
public void ExecuteRecipe(Plot plt) { // generate sample heights are based on https://ourworldindata.org/human-height Random rand = new(0); double[] values = ScottPlot.DataGen.RandomNormal(rand, pointCount: 1234, mean: 178.4, stdDev: 7.6); // create a histogram (double[] probabilities, double[] binEdges) = ScottPlot.Statistics.Common.Histogram(values, min: 140, max: 220, binSize: 1, density: true); double[] leftEdges = binEdges.Take(binEdges.Length - 1).ToArray(); // display histogram probabability as a bar plot var bar = plt.AddBar(values: probabilities, positions: leftEdges); bar.BarWidth = 1; bar.FillColor = ColorTranslator.FromHtml("#9bc3eb"); bar.BorderColor = ColorTranslator.FromHtml("#82add9"); // display histogram distribution curve as a line plot double[] densities = ScottPlot.Statistics.Common.ProbabilityDensity(values, binEdges); plt.AddScatterLines( xs: binEdges, ys: densities, color: Color.Black, lineWidth: 2, lineStyle: LineStyle.Dash); // customize the plot style plt.Title("Adult Male Height"); plt.YAxis.Label("Probability"); plt.XAxis.Label("Height (cm)"); plt.SetAxisLimits(yMin: 0); }
public void ExecuteRecipe(Plot plt) { // male and female heights are based on https://ourworldindata.org/human-height Random rand = new(0); double[] heightsMale = ScottPlot.DataGen.RandomNormal(rand, pointCount: 2345, mean: 178.4, stdDev: 7.6); double[] heightsFemale = ScottPlot.DataGen.RandomNormal(rand, pointCount: 1234, mean: 164.7, stdDev: 7.1); // calculate histograms for male and female datasets var histMale = new ScottPlot.Statistics.Histogram(heightsMale, min: 140, max: 210, binSize: 1); var histFemale = new ScottPlot.Statistics.Histogram(heightsFemale, min: 140, max: 210, binSize: 1); // plot histograms var barMale = plt.AddBar(values: histMale.countsFrac, positions: histMale.bins); barMale.BarWidth = histMale.binSize; barMale.FillColor = Color.FromArgb(50, Color.Blue); barMale.BorderLineWidth = 0; var barFemale = plt.AddBar(values: histFemale.countsFrac, positions: histFemale.bins); barFemale.BarWidth = histFemale.binSize; barFemale.FillColor = Color.FromArgb(50, Color.Red); barFemale.BorderLineWidth = 0; // plot probability function curves plt.AddScatterLines( xs: histMale.bins, ys: histMale.probability, color: Color.FromArgb(150, Color.Blue), lineWidth: 3, label: $"Male (n={heightsMale.Length:N0})"); plt.AddScatterLines( xs: histFemale.bins, ys: histFemale.probability, color: Color.FromArgb(150, Color.Red), lineWidth: 3, label: $"Female (n={heightsFemale.Length:N0})"); // customize styling plt.Title("Human Height by Sex"); plt.YLabel("Probability"); plt.XLabel("Height (cm)"); plt.Legend(location: ScottPlot.Alignment.UpperLeft); plt.SetAxisLimits(yMin: 0); }
public void ExecuteRecipe(Plot plt) { double[] values = { 23, -17, 19, -24, 22 }; var bar = plt.AddBar(values); bar.FillColor = Color.Green; bar.FillColorNegative = Color.Red; }
public void ExecuteRecipe(Plot plt) { double[] values = { 26, 20, 23, 7, 16 }; double[] positions = { 0, 1, 2, 3, 4 }; string[] labels = { "PHP", "JS", "C++", "GO", "VB" }; plt.AddBar(values, positions); plt.XTicks(positions, labels); plt.SetAxisLimits(yMin: 0); }
public void ExecuteRecipe(Plot plt) { // create sample data double[] values = { 26, 20, 23, 7, 16 }; // add a bar graph to the plot plt.AddBar(values); // adjust axis limits so there is no padding below the bar graph plt.SetAxisLimits(yMin: 0); }
public void ExecuteRecipe(Plot plt) { double[] values = DataGen.RandomNormal(0, 12, 5, 10); double[] offsets = Enumerable.Range(0, values.Length).Select(x => values.Take(x).Sum()).ToArray(); var bar = plt.AddBar(values); bar.ValueOffsets = offsets; bar.FillColorNegative = Color.Red; bar.FillColor = Color.Green; }
public void ExecuteRecipe(Plot plt) { // create sample data double[] valuesA = { 1, 2, 3, 2, 1, 2, 1 }; double[] valuesB = { 3, 3, 2, 1, 3, 2, 1 }; // to simulate stacking B on A, shift B up by A double[] valuesB2 = new double[valuesB.Length]; for (int i = 0; i < valuesB.Length; i++) { valuesB2[i] = valuesA[i] + valuesB[i]; } // plot the bar charts in reverse order (highest first) plt.AddBar(valuesB2); plt.AddBar(valuesA); // adjust axis limits so there is no padding below the bar graph plt.SetAxisLimits(yMin: 0); }
public void ExecuteRecipe(Plot plt) { double[] values = { 23, 17, 19, 24, 22 }; double[] yOffsets = { -100, -100, -100, -100, -100 }; var bar = plt.AddBar(values); bar.ValueOffsets = yOffsets; // adjust axis limits so there is no padding below the bar graph plt.SetAxisLimits(yMin: -100); }
public void ExecuteRecipe(Plot plt) { Func <double, string> customFormatter = y => $"Y={y:N2}"; double[] values = { 27.3, 23.1, 21.2, 16.1, 6.4, 19.2, 18.7, 17.3, 20.3, 13.1 }; var bar = plt.AddBar(values); bar.ShowValuesAboveBars = true; bar.ValueFormatter = customFormatter; plt.SetAxisLimits(yMin: 0); }
public void ExecuteRecipe(Plot plt) { // generate sample heights are based on https://ourworldindata.org/human-height Random rand = new(0); double[] values = ScottPlot.DataGen.RandomNormal(rand, pointCount: 1234, mean: 178.4, stdDev: 7.6); // create a histogram (double[] counts, double[] binEdges) = ScottPlot.Statistics.Common.Histogram(values, min: 140, max: 220, binSize: 1); double[] leftEdges = binEdges.Take(binEdges.Length - 1).ToArray(); // display histogram probabability as a bar plot var bar = plt.AddBar(values: counts, positions: leftEdges); bar.FillColor = ColorTranslator.FromHtml("#9bc3eb"); bar.BorderLineWidth = 0; // display histogram distribution curve as a line plot on a secondary Y axis double[] smoothEdges = ScottPlot.DataGen.Range(start: binEdges.First(), stop: binEdges.Last(), step: 0.1, includeStop: true); double[] smoothDensities = ScottPlot.Statistics.Common.ProbabilityDensity(values, smoothEdges, percent: true); var probPlot = plt.AddScatterLines( xs: smoothEdges, ys: smoothDensities, lineWidth: 2, label: "probability"); probPlot.YAxisIndex = 1; plt.YAxis2.Ticks(true); // display vertical lines at points of interest var stats = new ScottPlot.Statistics.BasicStats(values); plt.AddVerticalLine(stats.Mean, Color.Black, 2, LineStyle.Solid, "mean"); plt.AddVerticalLine(stats.Mean - stats.StDev, Color.Black, 2, LineStyle.Dash, "1 SD"); plt.AddVerticalLine(stats.Mean + stats.StDev, Color.Black, 2, LineStyle.Dash); plt.AddVerticalLine(stats.Mean - stats.StDev * 2, Color.Black, 2, LineStyle.Dot, "2 SD"); plt.AddVerticalLine(stats.Mean + stats.StDev * 2, Color.Black, 2, LineStyle.Dot); plt.AddVerticalLine(stats.Min, Color.Gray, 1, LineStyle.Dash, "min/max"); plt.AddVerticalLine(stats.Max, Color.Gray, 1, LineStyle.Dash); plt.Legend(location: Alignment.UpperRight); // customize the plot style plt.Title("Adult Male Height"); plt.YAxis.Label("Count (#)"); plt.YAxis2.Label("Probability (%)"); plt.XAxis.Label("Height (cm)"); plt.SetAxisLimits(yMin: 0); plt.SetAxisLimits(yMin: 0, yAxisIndex: 1); }
public void ExecuteRecipe(Plot plt) { // create sample data double[] values = { 27.3, 23.1, 21.2, 16.1, 6.4, 19.2, 18.7, 17.3, 20.3, 13.1 }; // add a bar graph to the plot and enable values to be displayed above each bar var bar = plt.AddBar(values); bar.ShowValuesAboveBars = true; // adjust axis limits so there is no padding below the bar graph plt.SetAxisLimits(yMin: 0); }
public void ExecuteRecipe(Plot plt) { // add a bar graph to the plot double[] values = { 26, 20, 23, 7, 16 }; var bar = plt.AddBar(values); // add errorbars to the bar graph and customize styling as desired double[] errors = { 3, 2, 5, 1, 3 }; bar.ValueErrors = errors; bar.ErrorCapSize = .1; // adjust axis limits so there is no padding below the bar graph plt.SetAxisLimits(yMin: 0); }
public void ExecuteRecipe(Plot plt) { // create sample data double[] values = { 26, 20, 23, 7, 16 }; double[] positions = { 10, 20, 30, 40, 50 }; // add a bar graph to the plot var bar = plt.AddBar(values, positions); // customize the width of bars (80% of the inter-position distance looks good) bar.BarWidth = (positions[1] - positions[0]) * .8; // adjust axis limits so there is no padding below the bar graph plt.SetAxisLimits(yMin: 0); }
public void ExecuteRecipe(Plot plt) { // create sample data double[] values = { 26, 20, 23, 7, 16 }; double[] errors = { 3, 2, 5, 1, 3 }; double[] positions = { 1, 2, 3, 4, 5 }; // add a bar graph to the plot and customize it to render horizontally var bar = plt.AddBar(values, errors, positions); bar.Orientation = Orientation.Horizontal; // adjust axis limits so there is no padding to the left of the bar graph plt.SetAxisLimits(xMin: 0); }
public void ExecuteRecipe(Plot plt) { // generate sample heights are based on https://ourworldindata.org/human-height Random rand = new(0); double[] heights = ScottPlot.DataGen.RandomNormal(rand, pointCount: 1234, mean: 178.4, stdDev: 7.6); // create a histogram var hist = new ScottPlot.Statistics.Histogram(heights, min: 140, max: 220, binSize: 1); // display the histogram counts as a bar plot var bar = plt.AddBar(hist.counts, hist.bins); bar.BarWidth = hist.binSize; // customize the plot style plt.YAxis.Label("Count (#)"); plt.XAxis.Label("Height (cm)"); plt.SetAxisLimits(yMin: 0); }
public void ExecuteRecipe(Plot plt) { // generate sample heights are based on https://ourworldindata.org/human-height Random rand = new(0); double[] values = ScottPlot.DataGen.RandomNormal(rand, pointCount: 1234, mean: 178.4, stdDev: 7.6); // create a histogram (double[] counts, double[] binEdges) = ScottPlot.Statistics.Common.Histogram(values, min: 140, max: 220, binSize: 1); double[] leftEdges = binEdges.Take(binEdges.Length - 1).ToArray(); // display the histogram counts as a bar plot var bar = plt.AddBar(values: counts, positions: leftEdges); bar.BarWidth = 1; // customize the plot style plt.YAxis.Label("Count (#)"); plt.XAxis.Label("Height (cm)"); plt.SetAxisLimits(yMin: 0); }