public void Test_SMA_Candlestick() { Random rand = new Random(0); double[] xs = DataGen.Consecutive(150); OHLC[] ohlcs = DataGen.RandomStockPrices(rand, xs.Length); double[] sma20 = ScottPlot.Statistics.Finance.SMA(ohlcs, 20); double[] sma50 = ScottPlot.Statistics.Finance.SMA(ohlcs, 50); // replace timestamps with a series of numbers starting at 0 for (int i = 0; i < ohlcs.Length; i++) { ohlcs[i].time = i; } var plt = new ScottPlot.Plot(600, 400); plt.PlotCandlestick(ohlcs); plt.PlotScatter(xs, sma20, label: "20 day SMA", color: Color.Blue, markerSize: 0, lineWidth: 2); plt.PlotScatter(xs, sma50, label: "50 day SMA", color: Color.Maroon, markerSize: 0, lineWidth: 2); plt.Title("Simple Moving Average (SMA)"); plt.YLabel("Price"); plt.XLabel("Days"); plt.Legend(); plt.AxisAutoX(.03); TestTools.SaveFig(plt); }
public void Test_RGB_analysis() { Random rand = new Random(0); double[] ys = DataGen.RandomWalk(rand, 100); var plt = new ScottPlot.Plot(400, 300); plt.Style(figBg: System.Drawing.Color.Gray, dataBg: System.Drawing.Color.Gray); plt.PlotSignal(ys, yOffset: 0, color: System.Drawing.Color.FromArgb(255, 0, 0), label: "red", lineWidth: 2); plt.PlotSignal(ys, yOffset: 1, color: System.Drawing.Color.FromArgb(0, 255, 0), label: "green", lineWidth: 3); plt.PlotSignal(ys, yOffset: 2, color: System.Drawing.Color.FromArgb(0, 0, 255), label: "blue", lineWidth: 4); plt.PlotSignal(ys, yOffset: 3, color: System.Drawing.Color.FromArgb(0, 0, 0), label: "black"); plt.PlotSignal(ys, yOffset: 4, color: System.Drawing.Color.FromArgb(255, 255, 255), label: "white"); plt.Legend(); System.Drawing.Bitmap bmp = plt.Render(); var means = MeanPixel(bmp); Console.WriteLine($"mean bitmap intensity (ARGB): {means.A}, {means.R}, {means.G}, {means.B}"); // mean bitmap intensity (ARGB): 255, 123.4157, 124.8481, 126.327066666667 Assert.AreEqual(means.A, 255); // image is not transparent Assert.Greater(means.B, means.G); // blue line is thicker than green line Assert.Greater(means.G, means.R); // green line is thicker than red line }
public void Test_Bollinger_Bands() { Random rand = new Random(0); double[] xs = DataGen.Consecutive(150); OHLC[] ohlcs = DataGen.RandomStockPrices(rand, xs.Length); (var sma, var bolL, var bolU) = ScottPlot.Statistics.Finance.Bollinger(ohlcs); // replace timestamps with a series of numbers starting at 0 for (int i = 0; i < ohlcs.Length; i++) { ohlcs[i].time = i; } var plt = new ScottPlot.Plot(600, 400); plt.PlotCandlestick(ohlcs); plt.PlotFill(xs, bolL, xs, bolU, fillColor: Color.Blue, fillAlpha: .1); plt.PlotScatter(xs, bolL, color: Color.Navy, markerSize: 0); plt.PlotScatter(xs, bolU, color: Color.Navy, markerSize: 0); plt.PlotScatter(xs, sma, color: Color.Navy, markerSize: 0, lineStyle: LineStyle.Dash); plt.Title("Bollinger Bands"); plt.YLabel("Price"); plt.XLabel("Days"); plt.Legend(); plt.AxisAutoX(.03); TestTools.SaveFig(plt); }
public void SaveScottPlotTestFromWebsite() { string saveFileLocation = "C:\\Temp\\Quickstart_Quickstart_Scatter.png"; var plt = new ScottPlot.Plot(600, 400); int pointCount = 51; double[] xs = DataGen.Consecutive(pointCount); double[] sin = DataGen.Sin(pointCount); double[] cos = DataGen.Cos(pointCount); plt.AddScatter(sin, cos, label: "sin"); plt.AddScatter(xs, cos, label: "cos"); plt.Legend(); plt.Title("Scatter Plot Quickstart"); plt.YLabel("Vertical Units"); plt.XLabel("Horizontal Units"); plt.SaveFig(saveFileLocation); Assert.IsTrue(System.IO.File.Exists(saveFileLocation)); System.IO.File.Delete(saveFileLocation); }
public void Test_Legend_Style() { var plt1 = new ScottPlot.Plot(600, 400); plt1.PlotScatter(DataGen.Sin(10), DataGen.Sin(10), label: "sin", color: Color.Black, lineWidth: 1); plt1.Legend(); var mean1 = TestTools.MeanPixel(plt1.GetBitmap()); var plt2 = new ScottPlot.Plot(600, 400); plt2.PlotScatter(DataGen.Sin(10), DataGen.Sin(10), label: "sin", color: Color.Black, lineWidth: 2); plt2.Legend(); var mean2 = TestTools.MeanPixel(plt2.GetBitmap()); // thicker line means darker pixel intensity Assert.Less(mean2.R, mean1.R); var plt3 = new ScottPlot.Plot(600, 400); plt3.PlotScatter(DataGen.Sin(10), DataGen.Sin(10), label: "sin", color: Color.Gray, lineWidth: 2); plt3.Legend(); var mean3 = TestTools.MeanPixel(plt3.GetBitmap()); // lighter color means greater pixel intensity Assert.Greater(mean3.R, mean2.R); }
// Disabled because this test fails on Linux and MacOS due to a System.Drawing limitation //[Test] public void Test_Legend_Bold() { var plt = new ScottPlot.Plot(600, 400); plt.PlotScatter(DataGen.Consecutive(51), DataGen.Sin(51), label: "sin"); plt.PlotScatter(DataGen.Consecutive(51), DataGen.Cos(51), label: "cos"); plt.Legend(); var meanRegular = TestTools.MeanPixel(plt.GetBitmap()); plt.Legend(bold: true); var meanBold = TestTools.MeanPixel(plt.GetBitmap()); // bold text will darken the mean pixel intensity Assert.Less(meanBold.R, meanRegular.R); }
public void Test_Window_Functions() { var plt = new ScottPlot.Plot(500, 400); double[] xs = ScottPlot.DataGen.Range(-1, 1, .01, true); plt.PlotScatter(xs, FftSharp.Window.Hanning(xs.Length), label: "Hanning"); plt.PlotScatter(xs, FftSharp.Window.Hamming(xs.Length), label: "Hamming"); plt.PlotScatter(xs, FftSharp.Window.Bartlett(xs.Length), label: "Bartlett"); plt.PlotScatter(xs, FftSharp.Window.Blackman(xs.Length), label: "Blackman"); //plt.PlotScatter(xs, FftSharp.Window.BlackmanExact(xs.Length), label: "BlackmanExact"); //plt.PlotScatter(xs, FftSharp.Window.BlackmanHarris(xs.Length), label: "BlackmanHarris"); plt.PlotScatter(xs, FftSharp.Window.FlatTop(xs.Length), label: "FlatTop"); plt.PlotScatter(xs, FftSharp.Window.Cosine(xs.Length), label: "Cosine"); // customize line styles post-hoc foreach (var p in plt.GetPlottables()) { if (p is ScottPlot.PlottableScatter) { ((ScottPlot.PlottableScatter)p).markerSize = 0; ((ScottPlot.PlottableScatter)p).lineWidth = 3; var c = ((ScottPlot.PlottableScatter)p).color; ((ScottPlot.PlottableScatter)p).color = System.Drawing.Color.FromArgb(200, c.R, c.G, c.B); } } plt.Legend(location: ScottPlot.legendLocation.upperRight); plt.SaveFig("../../../../../dev/windows.png"); }
public void Test_Bar_MultiSeries() { Random rand = new Random(0); string[] groupNames = { "one", "two", "three", "four", "five" }; string[] seriesNames = { "alpha", "beta", "gamma" }; int groupCount = groupNames.Length; double[] xs = DataGen.Consecutive(groupCount); double[] ys1 = DataGen.RandomNormal(rand, groupCount, 20, 5); double[] ys2 = DataGen.RandomNormal(rand, groupCount, 20, 5); double[] ys3 = DataGen.RandomNormal(rand, groupCount, 20, 5); double[] err1 = DataGen.RandomNormal(rand, groupCount, 5, 2); double[] err2 = DataGen.RandomNormal(rand, groupCount, 5, 2); double[] err3 = DataGen.RandomNormal(rand, groupCount, 5, 2); var plt = new ScottPlot.Plot(600, 400); plt.PlotBarGroups( groupLabels: groupNames, seriesLabels: seriesNames, ys: new double[][] { ys1, ys2, ys3 }, yErr: new double[][] { err1, err2, err3 }); plt.Axis(y1: 0); plt.Grid(enableVertical: false, lineStyle: LineStyle.Dot); plt.Legend(location: Alignment.UpperRight); TestTools.SaveFig(plt); }
public void Test_SaveFig_OutputScaling() { var plt = new ScottPlot.Plot(); plt.AddSignal(DataGen.Sin(51), label: "sin"); plt.AddSignal(DataGen.Cos(51), label: "cos"); plt.Title("Scaled Figure Demo"); plt.XLabel("Horizontal Axis"); plt.YLabel("Vertical Axis"); plt.Legend(); System.Drawing.Bitmap bmpA = plt.Render(400, 300); Assert.AreEqual(400, bmpA.Width); Assert.AreEqual(300, bmpA.Height); System.Drawing.Bitmap bmpB = plt.Render(400, 300, scale: .5); Assert.AreEqual(200, bmpB.Width); Assert.AreEqual(150, bmpB.Height); System.Drawing.Bitmap bmpC = plt.Render(400, 300, scale: 2); Assert.AreEqual(800, bmpC.Width); Assert.AreEqual(600, bmpC.Height); System.Drawing.Bitmap bmpD = plt.Render(300, 400, scale: 2); Assert.AreEqual(600, bmpD.Width); Assert.AreEqual(800, bmpD.Height); System.Drawing.Bitmap legendNormal = plt.RenderLegend(); System.Drawing.Bitmap legendBig = plt.RenderLegend(scale: 2); Assert.Greater(legendBig.Width, legendNormal.Width); Assert.Greater(legendBig.Height, legendNormal.Height); }
public void Test_PlottablePopulations_Population() { // This example will display a single population: mean age of every country in europe in 2007 // This example has 1 series that contains 1 population. // for this example we will simulate countries by creating random data Random rand = new Random(0); var ages = new Population(rand, 44, 78, 2); var customPlottable = new PopulationPlot(ages); // plot the multi-series var plt = new ScottPlot.Plot(400, 300); plt.Add(customPlottable); plt.XAxis.Ticks(false); // additional plot styling plt.Title("Life Expectancy in European Countries in 2007"); plt.YLabel("Age (years)"); plt.Legend(location: Alignment.LowerRight); plt.Grid(lineStyle: LineStyle.Dot); plt.XAxis.Grid(false); TestTools.SaveFig(plt); }
public void Test_PlottablePopulations_Series() { // This example will display age, grouped by location. // This example has 1 series that contains 5 population objects. // for this example we will simulate countries by creating random data Random rand = new Random(0); var ages = new Population[] { new Population(rand, 54, 53, 5), // africa new Population(rand, 35, 72, 3), // americas new Population(rand, 48, 72, 4), // asia new Population(rand, 44, 78, 2), // europe new Population(rand, 14, 81, 1), // oceania }; var customPlottable = new PopulationPlot(ages, color: System.Drawing.Color.CornflowerBlue); // plot the multi-series var plt = new ScottPlot.Plot(); plt.Add(customPlottable); plt.XTicks(labels: new string[] { "Africas", "Americas", "Asia", "Europe", "Oceania" }); plt.XAxis.TickLabelStyle(fontSize: 18); plt.YAxis.TickLabelStyle(fontSize: 18); // additional plot styling plt.XAxis2.Label(label: "Life Expectancy in 2007", size: 26); plt.YAxis.Label(label: "Age (years)", size: 18); plt.Legend(location: Alignment.LowerRight); plt.Grid(lineStyle: LineStyle.Dot); plt.XAxis.Grid(false); TestTools.SaveFig(plt); }
public void Test_Bollinger_Bands() { Random rand = new Random(0); double[] xs = DataGen.Consecutive(150); OHLC[] ohlcs = DataGen.RandomStockPrices(rand, xs.Length); // calculate moving average X and Ys (var sma, var bolL, var bolU) = ScottPlot.Statistics.Finance.Bollinger(ohlcs, 20); double[] xs2 = xs.Skip(20).ToArray(); // replace timestamps with a series of numbers starting at 0 for (int i = 0; i < ohlcs.Length; i++) { ohlcs[i].DateTime = DateTime.FromOADate(i); } var plt = new ScottPlot.Plot(600, 400); plt.AddCandlesticks(ohlcs); plt.AddFill(xs2, bolL, xs2, bolU, color: Color.FromArgb(10, Color.Blue)); plt.AddScatter(xs2, bolL, color: Color.Navy, markerSize: 0, label: "Bollinger Bands"); plt.AddScatter(xs2, bolU, color: Color.Navy, markerSize: 0); plt.AddScatter(xs2, sma, color: Color.Navy, markerSize: 0, lineStyle: LineStyle.Dash, label: "SMA 20"); plt.Title("Moving Average and Standard Deviation"); plt.YLabel("Price"); plt.XLabel("Days"); plt.Legend(); plt.AxisAutoX(.03); TestTools.SaveFig(plt); }
public void Test_Scatter_Simple() { var plt = new ScottPlot.Plot(500, 300); plt.PlotSignal(DataGen.Sin(51), label: "sin"); plt.PlotSignal(DataGen.Cos(51), label: "cos"); plt.Legend(); TestTools.SaveFig(plt); }
private void FillDemoPlots() { Random rand = new Random(); if (true) { var plt = new ScottPlot.Plot(600, 400); int pointCount = 51; double[] xs = DataGen.Consecutive(pointCount); double[] sin = DataGen.Sin(pointCount); double[] cos = DataGen.Cos(pointCount); plt.PlotScatter(xs, sin, label: "sin"); plt.PlotScatter(xs, cos, label: "cos"); plt.Legend(); plt.Title("Scatter Plot Quickstart"); plt.YLabel("Vertical Units"); plt.XLabel("Horizontal Units"); var pv1 = new ScottPlot.WpfPlot(); pv1.Height = 200; plt.Title("Scatter Plot Quickstart"); plt.YLabel("Vertical Units"); plt.XLabel("Horizontal Units"); StackPanelCharts.Children.Add(pv1); } if (true) { var pv1 = new ScottPlot.WpfPlot(); pv1.Height = 200; pv1.plt.PlotSignal(DataGen.RandomWalk(rand, 100)); var plt = pv1.plt; int pointCount = 51; double[] xs = DataGen.Consecutive(pointCount); double[] sin = DataGen.Sin(pointCount); double[] cos = DataGen.Cos(pointCount); plt.PlotScatter(xs, sin, label: "sin"); plt.PlotScatter(xs, cos, label: "cos"); plt.Legend(); plt.Title("Scatter Plot Quickstart"); plt.YLabel("Vertical Units"); plt.XLabel("Horizontal Units"); StackPanelCharts.Children.Add(pv1); } }
public void Test_Legend_RequestBeforeRender() { var plt = new ScottPlot.Plot(600, 400); plt.PlotScatter(DataGen.Consecutive(51), DataGen.Sin(51), label: "sin"); plt.PlotScatter(DataGen.Consecutive(51), DataGen.Cos(51), label: "cos"); plt.Legend(); System.Drawing.Bitmap bmpLegend = plt.GetLegendBitmap(); Assert.Less(bmpLegend.Width, 600); Assert.Less(bmpLegend.Height, 400); }
static public void RunJolka(List <Solver <string> > backtracks, List <Solver <string> > backtrackfws, string heuristicB = "", string heuristicBF = "", string type = "") { var plt = new ScottPlot.Plot(1280, 720); List <double> xlist = new List <double>(); List <double> yfwlist = new List <double>(); List <double> ylist = new List <double>(); foreach (var el in backtrackfws) { xlist.Add(el.solvedPuzzle.Puzzle.id); if (type == "time") { yfwlist.Add(el.solvedPuzzle.elapsed.TotalMilliseconds); } else { yfwlist.Add(el.solvedPuzzle.Puzzle.steps); } } foreach (var el in backtracks) { if (type == "time") { ylist.Add(el.solvedPuzzle.elapsed.TotalMilliseconds); } else { ylist.Add(el.solvedPuzzle.Puzzle.steps); } } double[] xs = xlist.ToArray(); ylist.Insert(2, (double)1); double[] dataB = Tools.Log10(ylist.ToArray()); double[] dataBF = Tools.Log10(yfwlist.ToArray()); plt.PlotBar(xs, dataB, label: "Backtrack w/ " + heuristicB, barWidth: .3, xOffset: -0.2, showValues: true); plt.PlotBar(xs, dataBF, label: "Backtrack with forward w/ " + heuristicBF, barWidth: .3, xOffset: 0.2, showValues: true); plt.Title(type + " over Jolka id"); plt.Ticks(useExponentialNotation: false, useMultiplierNotation: false, logScaleY: true); plt.Axis(y1: 0); plt.XTicks(new string[] { "0", "1", "2", "3", "4" }); if (type == "time") { plt.YLabel("Execution time [10 ^ y ms]"); } else { plt.YLabel("Steps [10 ^ y]"); } plt.XLabel("Jolka ID"); plt.Legend(location: legendLocation.upperRight); plt.SaveFig(heuristicB + heuristicBF + type + "JolkaBvsBF" + ".png"); }
public void Test_AxisLine_FarAwayExpandXY() { Random rand = new Random(0); var plt = new ScottPlot.Plot(); var data = DataGen.RandomWalk(rand, 100); plt.PlotSignal(data, xOffset: 100, yOffset: 100, label: "scatter"); plt.PlotVLine(-100, label: "vertical"); plt.PlotHLine(-100, label: "horizontal"); plt.Legend(); TestTools.SaveFig(plt); }
static void Main(string[] args) { BendStiffener bendStiffener = new BendStiffener { max_k = 0.3f, D1 = 0.7, d1 = 0.18, d2 = 0.2, L1 = 0.1, L2 = 2.3, L3 = 0.2, EIp = 1e4, Es = 4.5e6, F = 2e4, q = 0.52 }; int N = 10000; Vector <double>[] res = bendStiffener.bvpsolver_zzz(bendStiffener.Ode_to_solve, 0.0, bendStiffener.q, 0.0, 5.0, N); double[] x = Vector <double> .Build.Dense(N, i => i * 5.0 / N).ToArray(); double[] y = new double[N]; double[] dydx = new double[N]; for (int i = 0; i < N; i++) { double[] temp = res[i].ToArray(); y[i] = temp[0]; dydx[i] = temp[1]; //Console.WriteLine(t[i]); } var plt = new ScottPlot.Plot(800, 600); //plt.PlotScatter(x, y, label: "y", markerShape: (MarkerShape)Enum.Parse(typeof(MarkerShape), "none")); plt.PlotScatter(x, dydx, label: "dydx", markerShape: (MarkerShape)Enum.Parse(typeof(MarkerShape), "none")); plt.Grid(false); plt.Legend(fontSize: 10); //plt.PlotSignal(new[,] { x, y }); plt.SaveFig("quickstart.png"); Console.WriteLine("plot finished"); // gives 164,537981852489 //Test //Console.WriteLine(y[N / 10]); // gives 164,537981852489 //Console.WriteLine(Math.Exp(-1) + 3 * Math.Exp(4) - 5.0 / 2 + 23.0 / 8); //gives 164,537329540604, which is y(1) Console.ReadKey(); }
private ScottPlot.Plot GetDemoPlot() { Random rand = new Random(0); var plt = new ScottPlot.Plot(); plt.AddScatter(DataGen.Random(rand, 100, 20), DataGen.Random(rand, 100, 5, 3), label: "scatter1"); plt.AddSignal(DataGen.RandomWalk(rand, 100), label: "signal1"); plt.AddScatter(DataGen.Random(rand, 100), ScottPlot.DataGen.Random(rand, 100), label: "scatter2"); plt.AddSignal(DataGen.RandomWalk(rand, 100), label: "signal2"); plt.AddVerticalLine(43, width: 4, label: "vline"); plt.AddHorizontalLine(1.23, width: 4, label: "hline"); plt.AddText("ScottPlot", 50, 0.25); plt.Legend(); return(plt); }
private ScottPlot.Plot GetDemoPlot() { Random rand = new Random(0); var plt = new ScottPlot.Plot(); plt.PlotScatter(ScottPlot.DataGen.Random(rand, 100, 20), ScottPlot.DataGen.Random(rand, 100, 5, 3), label: "scatter1"); plt.PlotSignal(ScottPlot.DataGen.RandomWalk(rand, 100), label: "signal1"); plt.PlotScatter(ScottPlot.DataGen.Random(rand, 100), ScottPlot.DataGen.Random(rand, 100), label: "scatter2"); plt.PlotSignal(ScottPlot.DataGen.RandomWalk(rand, 100), label: "signal2"); plt.PlotVLine(43, lineWidth: 4, label: "vline"); plt.PlotHLine(1.23, lineWidth: 4, label: "hline"); plt.PlotText("ScottPlot", 50, 0.25, rotation: -45, fontSize: 36, label: "text"); plt.Legend(); return(plt); }
/// <summary> /// Method for plotting data to .png /// </summary> /// <param name="dataPoints"></param> public static void Graph(double[,] dataPoints) { double[] DataError = new double[dataPoints.GetUpperBound(0) + 1]; double[] DataAccuracy = new double[dataPoints.GetUpperBound(0) + 1]; double[] dataXs = new double[dataPoints.GetUpperBound(0) + 1]; for (int i = 0; i < dataXs.Length; i++) { dataXs[i] = i; DataError[i] = dataPoints[i, 0]; DataAccuracy[i] = dataPoints[i, 1]; } /// plot the data /// var plt_acc = new ScottPlot.Plot(800, 600); var plt_loss = new ScottPlot.Plot(800, 600); plt_acc.PlotScatter(dataXs, DataAccuracy, label: "Accuracy"); plt_loss.PlotScatter(dataXs, DataError, label: "Error rate"); plt_acc.Grid(xSpacing: 20, ySpacing: .1); plt_loss.Grid(xSpacing: 5, ySpacing: .1); plt_acc.Legend(location: legendLocation.upperLeft); plt_loss.Legend(location: legendLocation.upperLeft); plt_acc.Title("Accuracy"); plt_loss.Title("Loss"); plt_acc.XLabel("Epoch"); plt_acc.YLabel("Accuracy"); plt_loss.XLabel("Epoch"); plt_loss.YLabel("Loss"); plt_acc.SaveFig("NN_acc.png"); plt_loss.SaveFig("NN_loss.png"); Process.Start(new ProcessStartInfo(@"NN_acc.png") { UseShellExecute = true }); Process.Start(new ProcessStartInfo(@"NN_loss.png") { UseShellExecute = true }); }
public void Test_Scatter_Smooth() { double[] xs = { 18.5, 20.6, 22.3, 24.5, 26.6, 15, 15 }; double[] ys = { 1.43, 1.48, 1.6, 1.59, 1.53, 1.52, 1.6 }; var plt = new ScottPlot.Plot(600, 400); var sp1 = plt.AddScatter(xs, ys, label: "DrawLines()"); sp1.Smooth = false; var sp2 = plt.AddScatter(xs, ys, label: "DrawCurve()"); sp2.Smooth = true; plt.Legend(); plt.SetAxisLimits(0, 30, 1.42, 1.62); TestTools.SaveFig(plt); }
public void Test_Legend_ReverseOrder() { var plt1 = new ScottPlot.Plot(); plt1.PlotSignal(DataGen.Sin(100), label: "sin"); plt1.PlotSignal(DataGen.Cos(100), label: "cos"); plt1.Legend(); string hash1 = ScottPlot.Tools.BitmapHash(plt1.GetBitmap()); var plt2 = new ScottPlot.Plot(); plt2.PlotSignal(DataGen.Sin(100), label: "sin"); plt2.PlotSignal(DataGen.Cos(100), label: "cos"); plt2.Legend(reverseOrder: true); string hash2 = ScottPlot.Tools.BitmapHash(plt2.GetBitmap()); Assert.AreNotEqual(hash1, hash2); }
public void Test_Legend_Render() { var plt = new ScottPlot.Plot(600, 400); plt.PlotScatter(DataGen.Consecutive(51), DataGen.Sin(51), label: "sin"); plt.PlotScatter(DataGen.Consecutive(51), DataGen.Cos(51), label: "cos"); var mean1 = TestTools.MeanPixel(plt.GetBitmap()); plt.Legend(); var mean2 = TestTools.MeanPixel(plt.GetBitmap()); // the legend should darken the mean pixel intensity Assert.AreEqual(mean2.A, mean1.A); Assert.Less(mean2.R, mean1.R); Assert.Less(mean2.G, mean1.G); Assert.Less(mean2.B, mean1.B); }
public void GenerateMultipleBoxAndWhiskers(List <List <ResultModel> > allResults, List <int> xValues, string plotTitle, string plotName = "results") { var plt = new ScottPlot.Plot(600, 400); var poulations = new ScottPlot.Statistics.Population[allResults.Count]; var p = 0; foreach (var results in allResults) { var ys = new double[results.Count]; var i = 0; foreach (var r in results) { ys[i] = r.Fitness; i++; } var pop = new ScottPlot.Statistics.Population(ys); poulations[p] = pop; p++; } var popSeries = new ScottPlot.Statistics.PopulationSeries(poulations); plt.PlotPopulations(popSeries, "scores"); // improve the style of the plot plt.Title(plotTitle); plt.YLabel("Solution energy"); var ticks = new string[xValues.Count]; var j = 0; foreach (var iterations in xValues) { ticks[j] = iterations.ToString(); j++; } plt.XTicks(ticks); plt.Legend(); plt.Grid(lineStyle: LineStyle.Dot, enableVertical: false); plt.SaveFig($"{plotName}.png"); }
public void Test_AxisLine_FarAwayExpandXY() { Random rand = new Random(0); var plt = new ScottPlot.Plot(); var data = DataGen.RandomWalk(rand, 100); var sig = plt.AddSignal(data); sig.OffsetX = 100; sig.OffsetY = 100; sig.Label = "scatter"; plt.AddVerticalLine(-100, label: "vertical"); plt.AddHorizontalLine(-100, label: "horizontal"); plt.Legend(); TestTools.SaveFig(plt); }
public void Test_SMA_DoubleArray() { Random rand = new Random(0); double[] xs = DataGen.Consecutive(150); double[] prices = DataGen.RandomWalk(rand, xs.Length, offset: 50); double[] sma20 = ScottPlot.Statistics.Finance.SMA(prices, 20); double[] sma50 = ScottPlot.Statistics.Finance.SMA(prices, 50); var plt = new ScottPlot.Plot(600, 400); plt.PlotScatter(xs, prices, lineWidth: 0, label: "Price"); plt.PlotScatter(xs, sma20, label: "20 day SMA", markerSize: 0, lineWidth: 2); plt.PlotScatter(xs, sma50, label: "50 day SMA", markerSize: 0, lineWidth: 2); plt.YLabel("Price"); plt.XLabel("Days"); plt.Legend(); TestTools.SaveFig(plt); }
static public void RunSudoku(double[] difficulty, double[] dataB, double[] dataBF, string heuristicB = "", string heuristicBF = "", string type = "") { var plt = new ScottPlot.Plot(1280, 720); int pointCount = dataB.Length; plt.PlotBar(difficulty, dataB, label: "Backtrack w/ " + heuristicB, barWidth: .3, xOffset: -0.2); plt.PlotBar(difficulty, dataBF, label: "Backtrack with forward w/ " + heuristicBF, barWidth: .3, xOffset: 0.2); plt.Title("Average " + type + " over sudoku difficulty"); plt.Axis(y1: 0); if (type == "time") { plt.YLabel("Execution time [ms]"); } else { plt.YLabel("Steps"); } plt.XLabel("Difficulty"); plt.Legend(location: legendLocation.upperRight); plt.Ticks(useExponentialNotation: false, useMultiplierNotation: false); plt.SaveFig(heuristicB + heuristicBF + type + "BvsBF" + ".png"); }
static void Main(string[] args) { int N = 10000; Vector <double> y0 = Vector <double> .Build.Dense(new[] { -7.0 / 4.0, 55.0 / 8.0 }); //Func<double, Vector<double>, Vector<double>> der = DerivativeMaker(); Vector <double>[] res = RungeKutta.FourthOrder(y0, 0, 10, N, DerivativeMaker_zzz2); double[] t = Vector <double> .Build.Dense(N, i => i * 10.0 / N).ToArray(); double[] x = new double[N]; double[] y = new double[N]; for (int i = 0; i < N; i++) { double[] temp = res[i].ToArray(); x[i] = temp[0]; y[i] = temp[1]; //Console.WriteLine(t[i]); } var plt = new ScottPlot.Plot(800, 600); plt.PlotScatter(t, x, label: "x", markerShape: (MarkerShape)Enum.Parse(typeof(MarkerShape), "none")); plt.PlotScatter(t, y, label: "y", markerShape: (MarkerShape)Enum.Parse(typeof(MarkerShape), "none")); plt.Grid(false); plt.Legend(fontSize: 10); //plt.PlotSignal(new[,] { x, y }); plt.SaveFig("quickstart.png"); //Test Console.WriteLine(y[N / 10]); // gives 164,537981852489 Console.WriteLine(Math.Exp(-1) + 3 * Math.Exp(4) - 5.0 / 2 + 23.0 / 8); //gives 164,537329540604, which is y(1) Console.ReadKey(); }
private void MakeAPlot(double[,] data, double[,] dataEmp) { var plt = new ScottPlot.Plot(1000, 800); double[] x, y1, y2, y3, y4, empX, empY1, empY2, empY3, empY4; int linewidth = 2, markersize = 0; x = GetColumn(data, 0); y1 = GetColumn(data, 1); y2 = GetColumn(data, 2); y3 = GetColumn(data, 3); y4 = GetColumn(data, 4); empX = GetRow(dataEmp, 0); empY1 = GetRow(dataEmp, 1); empY2 = GetRow(dataEmp, 2); empY3 = GetRow(dataEmp, 3); empY4 = GetRow(dataEmp, 4); plt.PlotScatter(x, y1, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Green, label: "Susceptible", lineStyle: LineStyle.Dot); plt.PlotScatter(x, y2, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Red, label: "Infected", lineStyle: LineStyle.Dot); plt.PlotScatter(x, y3, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Gray, label: "Vaccinated", lineStyle: LineStyle.Dot); plt.PlotScatter(x, y4, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Blue, label: "Recovered", lineStyle: LineStyle.Dot); plt.PlotScatter(empX, empY1, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Green, label: "Susceptible emp"); plt.PlotScatter(empX, empY2, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Red, label: "Infected emp"); plt.PlotScatter(empX, empY3, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Gray, label: "Vaccinated emp"); plt.PlotScatter(empX, empY4, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Blue, label: "Recovered emp"); //plt.PlotAnnotation("Population: " + N + "\nβ = " + beta + "\nγ = " + gamma, 10, 10); plt.Legend(); plt.XLabel("Time"); plt.YLabel("Population"); image.Source = CreateBitmapSourceFromGdiBitmap(plt.GetBitmap()); }