public void ExecuteRecipe(Plot plt) { plt.Palette = ScottPlot.Palette.ColorblindFriendly; // generate random data System.Random rand = new(12345); var xs = ScottPlot.DataGen.RandomWalk(rand, 20); var ys = ScottPlot.DataGen.RandomWalk(rand, 20); plt.AddScatter(xs, ys, lineStyle: ScottPlot.LineStyle.Dash, markerSize: 10, label: "original"); // interpolate the same data in different ways (double[] bzX, double[] bzY) = ScottPlot.Statistics.Interpolation.Bezier.InterpolateXY(xs, ys, .005); (double[] crX, double[] crY) = ScottPlot.Statistics.Interpolation.CatmullRom.InterpolateXY(xs, ys, 15); (double[] chX, double[] chY) = ScottPlot.Statistics.Interpolation.Chaikin.InterpolateXY(xs, ys, 4); (double[] cbX, double[] cbY) = ScottPlot.Statistics.Interpolation.Cubic.InterpolateXY(xs, ys, 200); // display the different curves as line plots plt.AddScatterLines(bzX, bzY, lineWidth: 2, label: $"Bezier"); plt.AddScatterLines(crX, crY, lineWidth: 2, label: $"Catmull-Rom"); plt.AddScatterLines(chX, chY, lineWidth: 2, label: $"Chaikin"); plt.AddScatterLines(cbX, cbY, lineWidth: 2, label: $"Cubic"); // style the plot plt.Legend(); plt.Frameless(); plt.Grid(false); plt.XAxis2.Label("Spline Interpolation", size: 28, bold: true); }
public void ExecuteRecipe(Plot plt) { OHLC[] ohlcs = DataGen.RandomStockPrices(null, 100); var candlePlot = plt.AddCandlesticks(ohlcs); var bol = candlePlot.GetBollingerBands(20); plt.AddScatterLines(bol.xs, bol.sma, Color.Blue); plt.AddScatterLines(bol.xs, bol.lower, Color.Blue, lineStyle: LineStyle.Dash); plt.AddScatterLines(bol.xs, bol.upper, Color.Blue, lineStyle: LineStyle.Dash); }
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) { OHLC[] ohlcs = DataGen.RandomStockPrices(null, 75); var candlePlot = plt.AddCandlesticks(ohlcs); var sma8 = candlePlot.GetSMA(8); plt.AddScatterLines(sma8.xs, sma8.ys, Color.Blue, 2); var sma20 = candlePlot.GetSMA(20); plt.AddScatterLines(sma20.xs, sma20.ys, Color.Navy, 2); }
public void ExecuteRecipe(Plot plt) { // add some random candles OHLC[] prices = DataGen.RandomStockPrices(null, 100, TimeSpan.FromMinutes(5)); double[] xs = prices.Select(x => x.DateTime.ToOADate()).ToArray(); var candlePlot = plt.AddCandlesticks(prices); candlePlot.YAxisIndex = 1; plt.XAxis.DateTimeFormat(true); // add SMA indicators for 8 and 20 days var sma8 = candlePlot.GetSMA(8); var sma20 = candlePlot.GetSMA(20); var sma8plot = plt.AddScatterLines(sma8.xs, sma8.ys, Color.Cyan, 2, label: "8 day SMA"); var sma20plot = plt.AddScatterLines(sma20.xs, sma20.ys, Color.Yellow, 2, label: "20 day SMA"); sma8plot.YAxisIndex = 1; sma20plot.YAxisIndex = 1; // customize candle styling candlePlot.ColorDown = ColorTranslator.FromHtml("#00FF00"); candlePlot.ColorUp = ColorTranslator.FromHtml("#FF0000"); // customize figure styling plt.Layout(padding: 12); plt.Style(figureBackground: Color.Black, dataBackground: Color.Black); plt.Frameless(); plt.XAxis.TickLabelStyle(color: Color.White); plt.XAxis.TickMarkColor(ColorTranslator.FromHtml("#333333")); plt.XAxis.MajorGrid(color: ColorTranslator.FromHtml("#333333")); // hide the left axis and show a right axis plt.YAxis.Ticks(false); plt.YAxis.Grid(false); plt.YAxis2.Ticks(true); plt.YAxis2.Grid(true); plt.YAxis2.TickLabelStyle(color: ColorTranslator.FromHtml("#00FF00")); plt.YAxis2.TickMarkColor(ColorTranslator.FromHtml("#333333")); plt.YAxis2.MajorGrid(color: ColorTranslator.FromHtml("#333333")); // customize the legend style var legend = plt.Legend(); legend.FillColor = Color.Transparent; legend.OutlineColor = Color.Transparent; legend.Font.Color = Color.White; legend.Font.Bold = true; }
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) { double[] xs = DataGen.Consecutive(51); double[] ys = DataGen.Sin(51); plt.AddScatterLines(xs, ys, Color.Red, 3); }
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) { // 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) { plt.Palette = ScottPlot.Drawing.Palette.Frost; for (int i = 0; i < plt.Palette.Count(); i++) { double[] xs = DataGen.Consecutive(100); double[] ys = DataGen.Sin(100, phase: -i * .5 / plt.Palette.Count()); plt.AddScatterLines(xs, ys, lineWidth: 3); } plt.Title($"{plt.Palette}"); plt.AxisAutoX(0); }
public void ExecuteRecipe(Plot plt) { plt.Palette = ScottPlot.Palette.PolarNight; for (int i = 0; i < plt.Palette.Count(); i++) { double[] xs = DataGen.Consecutive(100); double[] ys = DataGen.Sin(100, phase: -i * .5 / plt.Palette.Count()); plt.AddScatterLines(xs, ys, lineWidth: 3); } plt.Title($"{plt.Palette}"); plt.AxisAuto(0, 0.1); plt.Style(ScottPlot.Style.Blue2); }
public void ExecuteRecipe(Plot plt) { // custom colors generated using "i want hue" http://medialab.github.io/iwanthue/ string[] customColors = { "#019d9f", "#7d3091", "#57e075", "#e5b5fa", "#009118" }; // create a custom palette and set it in the plot module plt.Palette = new ScottPlot.Drawing.Palette(customColors); for (int i = 0; i < plt.Palette.Count(); i++) { double[] xs = DataGen.Consecutive(100); double[] ys = DataGen.Sin(100, phase: -i * .5 / plt.Palette.Count()); plt.AddScatterLines(xs, ys, lineWidth: 3); } plt.Title($"{plt.Palette}"); plt.AxisAutoX(0); }
public void ExecuteRecipe(Plot plt) { plt.Palette = ScottPlot.Drawing.Palette.OneHalfDark; for (int i = 0; i < plt.Palette.Count(); i++) { double[] xs = DataGen.Consecutive(100); double[] ys = DataGen.Sin(100, phase: -i * .5 / plt.Palette.Count()); plt.AddScatterLines(xs, ys, lineWidth: 3); } plt.Title($"{plt.Palette}"); plt.AxisAutoX(0); plt.Style(ScottPlot.Style.Gray1); var bnColor = System.Drawing.ColorTranslator.FromHtml("#2e3440"); plt.Style(figureBackground: bnColor, dataBackground: bnColor); }