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 static void PlotMonthlyChange(List <MonthlyClosedDifference> series, string propertyName, string folderName, string fileName) { // get and convert specific property of a list of objects to array of doubles PropertyInfo prop = typeof(MonthlyClosedDifference).GetProperty(propertyName); double[] valSeries = series.Select(x => Convert.ToDouble(prop.GetValue(x))).ToArray(); // months to x values and labels double[] x = DataGen.Consecutive(series.Count()); string[] labels = series.Select(x => x.Month).ToArray(); var plt = new ScottPlot.Plot(1000, 700); plt.Title(propertyName, fontName: "Segoe UI Light", color: Color.Black); plt.Ticks(dateTimeX: false, fontName: "Cascadia Mono"); plt.Grid(xSpacing: 1); // apply custom axis tick labels plt.XTicks(x, labels); // create folder if not exists System.IO.Directory.CreateDirectory(folderName); plt.PlotBar(x, valSeries, fillColor: Color.Orange); plt.SaveFig($"./{folderName}/{fileName}.png"); }
public static void PlotOHLC(List <StockHistoryDay> stockHistory, string folderName, string fileName) { List <ScottPlot.OHLC> valSeriesList = new List <ScottPlot.OHLC>(); foreach (StockHistoryDay stockHistoryDay in stockHistory) { ScottPlot.OHLC ohlc = new ScottPlot.OHLC( stockHistoryDay.Open, stockHistoryDay.High, stockHistoryDay.Low, stockHistoryDay.Close, stockHistoryDay.Date ); valSeriesList.Add(ohlc); } ScottPlot.OHLC[] valSeries = valSeriesList.ToArray(); var plt = new ScottPlot.Plot(1000, 700); plt.Title("MSFT", fontName: "Segoe UI Light", color: Color.Black); plt.Ticks(dateTimeX: true, fontName: "Cascadia Mono"); // grids at every 7 days plt.Grid(xSpacing: 7, xSpacingDateTimeUnit: ScottPlot.Config.DateTimeUnit.Day); plt.SetCulture(shortDatePattern: "M\\/dd"); // create folder if not exists System.IO.Directory.CreateDirectory(folderName); plt.PlotOHLC(valSeries); plt.SaveFig($"./{folderName}/{fileName}.png"); }
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 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_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 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_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_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 PlottablePopulations(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.Ticks(fontSize: 18); // additional plot styling plt.Title("Life Expectancy in 2007", fontSize: 26); plt.YLabel("Age (years)", fontSize: 18); plt.Legend(location: legendLocation.lowerRight); plt.Grid(lineStyle: LineStyle.Dot, enableVertical: false); TestTools.SaveFig(plt); }
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_DefinedSpacing_NumericAxis() { int pointCount = 20; // create a series of day numbers double[] days = ScottPlot.DataGen.Consecutive(pointCount); // simulate data for each date double[] values = new double[pointCount]; Random rand = new Random(0); for (int i = 1; i < pointCount; i++) { values[i] = values[i - 1] + rand.NextDouble(); } var pltDefault = new ScottPlot.Plot(); pltDefault.Title("Default xSpacing"); pltDefault.AddScatter(days, values); var pltTest = new ScottPlot.Plot(); pltTest.Title("xSpacing = 1 unit"); pltTest.AddScatter(days, values); // force inter-tick distance on a numerical axis pltTest.XAxis.ManualTickSpacing(1); //TestTools.SaveFig(pltDefault); //TestTools.SaveFig(pltTest); }
public void Test_Axis_ModeratelySmallNumbers() { var plt = new ScottPlot.Plot(400, 300); plt.Title("Moderately Small (e-8)"); double[] xs = { 1e-8, 2e-8, 3e-8, 4e-8 }; double[] ys = { 1e-8, 4e-8, 3e-8, 6e-8 }; plt.PlotScatter(xs, ys); TestTools.SaveFig(plt); }
public void Test_Axis_ExtremelySmallNumbers() { var plt = new ScottPlot.Plot(400, 300); plt.Title("Extremely Small (e-20)"); double[] xs = { 1e-20, 2e-20, 3e-20, 4e-20 }; double[] ys = { 1e-20, 4e-20, 3e-20, 6e-20 }; plt.PlotScatter(xs, ys); TestTools.SaveFig(plt); }
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"); }
/// <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_PolygonVsScatter_Alignment() { double[] xs = { 75, 250, 280, 100 }; double[] ys = { -100, -75, -200, -220 }; var plt = new ScottPlot.Plot(320, 240); plt.PlotPolygon(xs, ys, fillColor: Color.LightGreen); plt.PlotLine(xs[0], ys[0], xs[1], ys[1], Color.Blue); plt.Grid(false); plt.Frame(false); plt.Ticks(false, false); plt.Title("Line/Scatter"); TestTools.SaveFig(plt); }
public void Test_Layout() { int pointCount = 50; double[] dataXs = DataGen.Consecutive(pointCount); double[] dataSin = DataGen.Sin(pointCount); double[] dataCos = DataGen.Cos(pointCount); var plt = new ScottPlot.Plot(); plt.PlotScatter(dataXs, dataSin); plt.PlotScatter(dataXs, dataCos); plt.Title("Very Complicated Data"); plt.XLabel("Experiment Duration"); plt.YLabel("Productivity"); TestTools.SaveFig(plt); }
/// <summary> /// Return a new Plot with all the same Plottables (and some of the styles) of this one. /// </summary> public Plot Copy() { // This is typically only called when you right-click a plot in a control and hit "open in new window". // All state from the old plot must be copied to the new plot. Plot plt2 = new Plot(settings.Width, settings.Height); var settings2 = plt2.GetSettings(false); // Copying state of plottables is easy because they contain their own state. settings2.Plottables.AddRange(settings.Plottables); // TODO: copy axes, since they now carry their own state too. plt2.Title(settings.XAxis2.Title.Label); plt2.XLabel(settings.XAxis.Title.Label); plt2.YLabel(settings.YAxis.Title.Label); plt2.AxisAuto(); return(plt2); }
/// <summary> /// Return a new Plot with all the same Plottables (and some of the styles) of this one. /// This is called when you right-click a plot in a control and hit "open in new window". /// </summary> public Plot Copy() { Settings oldSettings = settings; Plot oldPlot = this; Plot newPlot = new Plot(oldSettings.Width, oldSettings.Height); foreach (IPlottable oldPlottable in oldPlot.GetPlottables()) { newPlot.Add(oldPlottable); } newPlot.AxisAuto(); newPlot.XLabel(oldSettings.XAxis.Label()); newPlot.YLabel(oldSettings.YAxis.Label()); newPlot.Title(oldSettings.XAxis2.Label()); return(newPlot); }
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_DefinedSpacing_DateTimeAxis() { int pointCount = 20; // create a series of dates double[] dates = new double[pointCount]; var firstDay = new DateTime(2020, 1, 22); for (int i = 0; i < pointCount; i++) { dates[i] = firstDay.AddDays(i).ToOADate(); } // simulate data for each date double[] values = new double[pointCount]; Random rand = new Random(0); for (int i = 1; i < pointCount; i++) { values[i] = values[i - 1] + rand.NextDouble(); } var pltDefault = new ScottPlot.Plot(); pltDefault.Title("Default xSpacing"); pltDefault.AddScatter(dates, values); pltDefault.XAxis.DateTimeFormat(true); var pltTest = new ScottPlot.Plot(); pltTest.Title("xSpacing = 1 day"); pltTest.AddScatter(dates, values); pltTest.XAxis.DateTimeFormat(true); pltTest.XAxis.TickLabelStyle(rotation: 45); pltTest.Layout(bottom: 60); // need extra height to accomodate rotated labels // force 1 tick per day on a DateTime axis pltTest.XAxis.ManualTickSpacing(1, ScottPlot.Ticks.DateTimeUnit.Day); //TestTools.SaveFig(pltDefault); //TestTools.SaveFig(pltTest); }
public void Test_Layout_LabelsWithLineBreaks() { int pointCount = 50; double[] dataXs = DataGen.Consecutive(pointCount); double[] dataSin = DataGen.Sin(pointCount); double[] dataCos = DataGen.Cos(pointCount); var plt = new ScottPlot.Plot(); plt.PlotScatter(dataXs, dataSin); plt.PlotScatter(dataXs, dataCos); string labelWithLineBreak = "Line One\nLine Two"; plt.Title(labelWithLineBreak, fontSize: 30); plt.XLabel(labelWithLineBreak); plt.YLabel(labelWithLineBreak); 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"); }
public void Test_PolygonVsSignal_AlignmentWithLargeValues() { double[] xs = { 1e6 + 75, 1e6 + 250, 1e6 + 280, 1e6 + 100 }; double[] ys = { 1e6 - 100, 1e6 - 75, 1e6 - 200, 1e6 - 220 }; var plt = new ScottPlot.Plot(320, 240); plt.PlotPolygon(xs, ys, fillColor: Color.LightGreen); plt.PlotSignal( ys: new double[] { ys[0], ys[1] }, sampleRate: 1.0 / (xs[1] - xs[0]), xOffset: xs[0], color: Color.Blue, markerSize: 0 ); plt.Grid(false); plt.Frame(false); plt.Ticks(false, false); plt.Title("Large Value Signal"); TestTools.SaveFig(plt); }
private ScottPlot.Plot TestColormap(Colorset cset, int lineWidth, bool dark = false) { var plt = new ScottPlot.Plot(600, 400); for (int i = 0; i < cset.Count(); i++) { double[] ys = DataGen.Sin(51, //mult: 1 - .5 * i / cset.Count(), phase: -i / Math.PI / cset.Count()); plt.PlotSignal(ys, color: cset.GetColor(i), markerSize: 0, lineWidth: lineWidth); } if (dark) { plt.Style(Style.Gray1); plt.Style(darkColor, darkColor); } plt.Title($"Colorset '{cset.Name}' has {cset.Count()} colors"); plt.AxisAuto(0); return(plt); }
private ScottPlot.Plot TestColormap(Palette cset, int lineWidth, bool dark = false) { var plt = new ScottPlot.Plot(600, 400); for (int i = 0; i < cset.Count(); i++) { double[] ys = DataGen.Sin(51, phase: -i / Math.PI / cset.Count()); var sig = plt.AddSignal(ys, color: cset.GetColor(i)); sig.MarkerSize = 0; sig.LineWidth = lineWidth; } if (dark) { plt.Style(Style.Gray1); plt.Style(darkColor, darkColor); } plt.Title($"Colorset '{cset.Name}' has {cset.Count()} colors"); plt.AxisAuto(0); return(plt); }
public void Test_PolygonVsSignal_AlignmentWithLargeValues() { double[] xs = { 1e6 + 75, 1e6 + 250, 1e6 + 280, 1e6 + 100 }; double[] ys = { 1e6 - 100, 1e6 - 75, 1e6 - 200, 1e6 - 220 }; var plt = new ScottPlot.Plot(320, 240); plt.AddPolygon(xs, ys, fillColor: Color.LightGreen); var sig = plt.AddSignal( ys: new double[] { ys[0], ys[1] }, sampleRate: 1.0 / (xs[1] - xs[0]), color: Color.Blue); sig.MarkerSize = 0; sig.OffsetX = xs[0]; plt.Grid(false); plt.Frameless(); plt.XAxis.Ticks(false); plt.YAxis.Ticks(false); plt.Title("Large Value Signal"); TestTools.SaveFig(plt); }
public void Test_scatter_10kPoints() { double[] pointCounts = { 10, 100, 1000, 10000 }; const int REPS = 10; double[] speeds = new double[pointCounts.Length]; for (int i = 0; i < pointCounts.Length; i++) { int pointCount = (int)pointCounts[i]; var plt = new ScottPlot.Plot(); Random rand = new Random(0); double[] xs = DataGen.Random(rand, pointCount); double[] ys = DataGen.RandomWalk(rand, pointCount); plt.AddScatter(xs, ys); plt.Render(lowQuality: true); List <double> times = new List <double>(); for (int j = 0; j < REPS; j++) { plt.Render(lowQuality: true); times.Add(plt.GetSettings(false).BenchmarkMessage.MSec); } var stats = new ScottPlot.Statistics.Population(times.ToArray()); speeds[i] = stats.mean; Console.WriteLine($"Rendered {pointCount} points in {stats.mean} ms"); } var plt2 = new ScottPlot.Plot(400, 300); plt2.Title("Scatter Plot Benchmark"); plt2.YLabel("Time (ms)"); plt2.XLabel("Number of Points"); plt2.AddScatter(pointCounts, speeds); TestTools.SaveFig(plt2); }
public void Test_PlottablePopulations_MultiSeries() { // This example will display age, grouped by location, and by year. // This example has 3 series (years), each of which has 5 population objects (locations). // for this example we will simulate countries by creating random data Random rand = new Random(0); // start by collecting series data as Population[] arrays var ages1957 = new Population[] { new Population(rand, 54, 42, 4), // africa new Population(rand, 35, 56, 6), // americas new Population(rand, 48, 47, 5), // asia new Population(rand, 44, 66, 2), // europe new Population(rand, 14, 70, 1), // oceania }; var ages1987 = new Population[] { new Population(rand, 54, 52, 8), // africa new Population(rand, 35, 70, 3), // americas new Population(rand, 48, 66, 3), // asia new Population(rand, 44, 75, 2), // europe new Population(rand, 14, 75, 1), // oceania }; var ages2007 = 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 }; // now create a PopulationSeries object for each series string[] groupLabels = new string[] { "Africa", "Americas", "Asia", "Europe", "Oceania" }; var series1957 = new PopulationSeries(ages1957, "1957", color: System.Drawing.Color.Red); var series1987 = new PopulationSeries(ages1987, "1987", color: System.Drawing.Color.Green); var series2007 = new PopulationSeries(ages2007, "2007", color: System.Drawing.Color.Blue); // now collect all the series into a MultiSeries var multiSeries = new PopulationSeries[] { series1957, series1987, series2007 }; var plottableMultiSeries = new PopulationMultiSeries(multiSeries); var customPlottable = new PlottablePopulations(plottableMultiSeries); // plot the multi-series var plt = new ScottPlot.Plot(); plt.Add(customPlottable); plt.XTicks(labels: groupLabels); plt.Ticks(fontSize: 18); // additional plot styling plt.Title("Life Expectancy", fontSize: 26); plt.YLabel("Age (years)", fontSize: 18); plt.Legend(location: legendLocation.lowerRight); plt.Grid(lineStyle: LineStyle.Dot, enableVertical: false); TestTools.SaveFig(plt); }
private void btnSubmitHilos_Click(object sender, EventArgs e) { txtResFact.Clear(); lblResponse.Text = ""; BigInteger numero = 0; int iteraciones = 0; try { numero = int.Parse(numeroFact.Text); iteraciones = int.Parse(numItera.Text); } catch (Exception) { numero = 0; iteraciones = 0; } if (numero > 0 && iteraciones > 0) { txtResFact.Visible = false; Dictionary <double[], string> response = new Dictionary <double[], string>(); lblError.Visible = false; string formated = string.Format("{0}", numero); //OBTENER Numero Hilos, Tiempo en ms , y el string con info completa response = Principal.ObtenerFactoriales(numero, iteraciones); //PARA GRAFICA var plt = new ScottPlot.Plot(600, 400); double[] tiempos = new double[response.Count]; double[] hilos = new double[response.Count]; int i = 0; foreach (double[] val in response.Keys) { hilos[i] = val[0]; tiempos[i] = val[1]; i++; } plt.PlotScatter(hilos, tiempos); plt.Legend(); plt.Title("Hilos vs Tiempo de Obtener Factorial"); plt.YLabel("Tiempo(ms)"); plt.XLabel("Hilos"); string nombreImagen = string.Format("../../{0}_{1}_Grafica.png", numero, iteraciones); try { plt.SaveFig(nombreImagen); lblConfirmed.Text = "Se ha guardado la gráfica en png"; } catch (Exception) { lblConfirmed.Text = "No se ha podido guardar la información"; } lblConfirmed.Visible = true; //IMPRIMIR EN FORMS foreach (string val in response.Values) { lblResponse.Text += string.Format($"{val} \n"); Console.WriteLine(val); } } else { lblError.Visible = true; } }