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 Test_scatter_benchmark() { int[] pointCounts = { 1000, 100, 10 }; const int REPS = 10; Random rand = new(0); for (int i = 0; i < pointCounts.Length; i++) { int pointCount = pointCounts[i]; var plt = new ScottPlot.Plot(); double[] xs = DataGen.Random(rand, pointCount); double[] ys = DataGen.RandomWalk(rand, pointCount); plt.AddScatter(xs, ys); plt.Render(lowQuality: true); for (int j = 0; j < REPS; j++) { plt.Render(lowQuality: true); } double[] renderTimes = plt.BenchmarkTimes(); Assert.AreEqual(REPS + 1, renderTimes.Length); double meanTime = renderTimes.Sum() / renderTimes.Length; Console.WriteLine($"Rendered {pointCount} points in {meanTime:N2} ms (n={renderTimes.Length})"); } }
public void Test_Scatter_Offset() { Random rand = new(0); double[] xs = DataGen.Random(rand, 20); double[] ys = DataGen.Random(rand, 20); var plt = new ScottPlot.Plot(400, 300); var scatter = plt.AddScatter(xs, ys); scatter.XError = DataGen.Random(rand, 20, .1); scatter.YError = DataGen.Random(rand, 20, .1); plt.AxisAuto(); var limits1 = plt.GetAxisLimits(); //TestTools.SaveFig(plt, "beforeOffset"); Assert.Less(limits1.XMax, 10); Assert.Less(limits1.YMax, 20); scatter.OffsetX = 10; scatter.OffsetY = 20; plt.AxisAuto(); var limits2 = plt.GetAxisLimits(); //TestTools.SaveFig(plt, "afterOffset"); Assert.Greater(limits2.XMax, 10); Assert.Greater(limits2.YMax, 20); }
public void ExecuteRecipe(Plot plt) { Random rand = new Random(0); double[] xs = DataGen.Random(rand, 50); double[] ys = DataGen.Random(rand, 50); var scatter = plt.AddScatterPoints(xs, ys, Color.Blue, 10); var vlines = new ScottPlot.Plottable.VLineVector(); vlines.Xs = new double[] { xs[1], xs[12], xs[35] }; vlines.Color = Color.Red; vlines.PositionLabel = true; vlines.PositionLabelBackground = vlines.Color; var hlines = new ScottPlot.Plottable.HLineVector(); hlines.Ys = new double[] { ys[1], ys[12], ys[35] }; hlines.Color = Color.DarkCyan; hlines.PositionLabel = true; hlines.PositionLabelBackground = hlines.Color; hlines.DragEnabled = true; plt.Add(scatter); plt.Add(vlines); plt.Add(hlines); }
public void ExecuteRecipe(Plot plt) { double[] largeXs = DataGen.Consecutive(100, spacing: 1e6); double[] largeYs = DataGen.Random(null, 100, multiplier: 1e6); plt.AddScatter(largeXs, largeYs); plt.XAxis.TickLabelNotation(offset: true); }
public void Render(Plot plt) { Random rand = new Random(0); int pointCount = 100; double[] largeXs = DataGen.Consecutive(pointCount, offset: 1e6); double[] largeYs = DataGen.Random(rand, pointCount, offset: 1e6); plt.PlotScatter(largeXs, largeYs); }
private static List <PlotData> GenerateGroupData(string group) { return(DataGen.Random(new Random(), 30) .Select(value => new PlotData { Group = group, Value = value, Time = DateTime.Now.AddDays(-value), }).ToList()); }
public void ExecuteRecipe(Plot plt) { Random rand = new Random(0); int pointCount = 50; double[] xs = DataGen.Consecutive(pointCount); double[] ys = DataGen.NoisyBellCurve(rand, pointCount); double[] yErr = DataGen.Random(rand, pointCount, multiplier: .2, offset: .05); plt.AddErrorBars(xs, ys, null, yErr, markerSize: 5); }
public void Render(Plot plt) { Random rand = new Random(0); int pointCount = 100; double[] largeXs = DataGen.Consecutive(pointCount, spacing: 1e6); double[] largeYs = DataGen.Random(rand, pointCount, multiplier: 1e6); plt.PlotScatter(largeXs, largeYs); plt.Ticks(useMultiplierNotation: false); }
public void ExecuteRecipe(Plot plt) { int pointCount = 20; Random rand = new Random(0); double[] xs = DataGen.Consecutive(pointCount); double[] ys = DataGen.RandomWalk(rand, pointCount, 2.0); double[] yErr = DataGen.Random(rand, pointCount, 1.0, 1.0); plt.AddScatter(xs, ys, Color.Blue); plt.AddFillError(xs, ys, yErr, Color.FromArgb(50, Color.Blue)); }
public DebounceView() { InitializeComponent(); PlotEventPasserThing.ChartDataUpdated += UpdateChart; SignalView.Configuration.LockVerticalAxis = true; SignalView.Configuration.Quality = ScottPlot.Control.QualityMode.High; SignalView.Plot.Frame(false); SignalView.Plot.SetViewLimits(0, 5000); SignalView.Plot.Layout(padding: 0); double[] xs = DataGen.Range(0, 5000, 1); // left button (raw) line double[] leftButtonData = DataGen.Random(new Random(), pointCount: 5000, multiplier: 0, offset: 1.25); var leftSignalPlot = SignalView.Plot.AddSignal(leftButtonData); leftSignalPlot.MarkerSize = 4; leftSignalPlot.Color = System.Drawing.Color.FromArgb(140, 103, 58, 183); // left button (debounced) var leftDebouncedSignalPlot = SignalView.Plot.AddSignal(leftButtonData); leftDebouncedSignalPlot.MarkerSize = 4; leftDebouncedSignalPlot.LineWidth = 3; leftDebouncedSignalPlot.Color = System.Drawing.Color.FromArgb(103, 58, 183); // right button (raw) line double[] rightButtonData = DataGen.Random(new Random(), pointCount: 5000, multiplier: 0, offset: 0); var rightSignalPlot = SignalView.Plot.AddSignal(rightButtonData); rightSignalPlot.MarkerSize = 4; rightSignalPlot.Color = System.Drawing.Color.FromArgb(140, 255, 109, 0); // right button (debounced) var rightDebouncedSignalPlot = SignalView.Plot.AddSignal(rightButtonData); rightDebouncedSignalPlot.MarkerSize = 4; rightDebouncedSignalPlot.LineWidth = 3; rightDebouncedSignalPlot.Color = System.Drawing.Color.FromArgb(255, 109, 0); // X Axis SignalView.Plot.XAxis.MinimumTickSpacing(1); SignalView.Plot.XAxis.Label("Milliseconds"); // Y Axis SignalView.Plot.YAxis.Grid(false); double[] ys = new double[] { 0, 1, 1.25, 2.25 }; string[] ylabels = new string[] { "released", "pressed", "released", "pressed" }; SignalView.Plot.YTicks(ys, ylabels); SignalView.Plot.SetAxisLimitsY(-0.1, 2.25 + 0.1); }
public System.Drawing.Bitmap Render(int width, int height) { Random rand = new Random(0); var mp = new MultiPlot(width: width, height: height, rows: 2, cols: 2); mp.GetSubplot(0, 0).PlotSignal(DataGen.Sin(50)); mp.GetSubplot(0, 1).PlotSignal(DataGen.Cos(50)); mp.GetSubplot(1, 0).PlotSignal(DataGen.Random(rand, 50)); mp.GetSubplot(1, 1).PlotSignal(DataGen.RandomWalk(rand, 50)); return(mp.GetBitmap()); }
public void ExecuteRecipe(Plot plt) { Random rand = new Random(0); int pointCount = 500; double[] xs = DataGen.Consecutive(pointCount); double[] ys = DataGen.Random(rand, pointCount); double tenthPercentile = Statistics.Common.Percentile(ys, 10); plt.Title("10th Percentile"); plt.AddScatter(xs, ys, lineWidth: 0, markerShape: MarkerShape.openCircle); plt.AddHorizontalLine(tenthPercentile, width: 3, style: LineStyle.Dash); }
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); }
public void ExecuteRecipe(Plot plt) { Random rand = new Random(0); const int n = 500; double[] ys = DataGen.Random(rand, n); double tenth_percentile = ScottPlot.Statistics.Common.Percentile(ys, 10); // Note that the 10th percentile is different from 10% lows, which is the average of the bottom 10% plt.AddSignal(ys, label: "Random Data"); plt.AddHorizontalLine(tenth_percentile, label: "10th Percentile"); plt.Legend(); }
public void ExecuteRecipe(Plot plt) { Random rand = new Random(0); int pointCount = 500; double[] xs = DataGen.Consecutive(pointCount); double[] ys = DataGen.Random(rand, pointCount); // A septile is a 7-quantile double secondSeptile = Statistics.Common.Quantile(ys, 2, 7); plt.Title("Second Septile"); plt.AddScatter(xs, ys, lineWidth: 0, markerShape: MarkerShape.openCircle); plt.AddHorizontalLine(secondSeptile, width: 3, style: LineStyle.Dash); }
public void ExecuteRecipe(Plot plt) { // create random data and display it with a scatter plot double[] xs = DataGen.Consecutive(50); double[] ys = DataGen.Random(new Random(0), 50); plt.AddScatter(xs, ys, label: "data"); // place the marker at the first data point var marker = plt.AddMarkerDraggable(xs[0], ys[0], MarkerShape.filledDiamond, 15, Color.Magenta); // constrain snapping to the array of data points marker.DragSnap = new ScottPlot.SnapLogic.Nearest2D(xs, ys); plt.Legend(); }
public void ExecuteRecipe(Plot plt) { Random rand = new Random(0); const int n = 500; double[] ys = DataGen.Random(rand, n); double second_septile = ScottPlot.Statistics.Common.Quantile(ys, 2, 7); // A septile is a 7-quantile plt.AddSignal(ys, label: "Random Data"); plt.AddHorizontalLine(second_septile, label: "2nd Septile"); plt.Legend(); }
public void ExecuteRecipe(Plot plt) { Random rand = new Random(0); int pointCount = 500; double[] xs = DataGen.Consecutive(pointCount); double[] ys = DataGen.Random(rand, pointCount); int n = 200; double nthValue = Statistics.Common.NthOrderStatistic(ys, n); plt.Title($"{n}th Smallest Value (of {pointCount})"); plt.AddScatter(xs, ys, lineWidth: 0, markerShape: MarkerShape.openCircle); plt.AddHorizontalLine(nthValue, width: 3, style: LineStyle.Dash); }
public void Test_Population_CurveSideways() { Random rand = new Random(0); var ages = new ScottPlot.Statistics.Population(rand, 44, 78, 2); double[] curveXs = DataGen.Range(ages.minus3stDev, ages.plus3stDev, .1); double[] curveYs = ages.GetDistribution(curveXs); var plt = new ScottPlot.Plot(400, 300); plt.PlotScatter(DataGen.Random(rand, ages.values.Length), ages.values, markerSize: 10, markerShape: MarkerShape.openCircle, lineWidth: 0); plt.PlotScatter(curveYs, curveXs, markerSize: 0); plt.Grid(lineStyle: LineStyle.Dot); TestTools.SaveFig(plt); }
public void ExecuteRecipe(Plot plt) { Random rand = new Random(0); const int n = 500; double[] ys = DataGen.Random(rand, n); int k = 200; double y = ScottPlot.Statistics.Common.NthOrderStatistic(ys, k); plt.AddSignal(ys, label: "Random Data"); plt.AddHorizontalLine(y, label: $"{k}th Order Statistic"); plt.Legend(); }
public ShowValueOnHover() { InitializeComponent(); // create a scatter plot from some random data and save it Random rand = new Random(0); int pointCount = 20; double[] xs = DataGen.Random(rand, pointCount); double[] ys = DataGen.Random(rand, pointCount, multiplier: 1_000); MyScatterPlot = wpfPlot1.Plot.AddScatterPoints(xs, ys); // Add a red circle we can move around later as a highlighted point indicator HighlightedPoint = wpfPlot1.Plot.AddPoint(0, 0); HighlightedPoint.Color = System.Drawing.Color.Red; HighlightedPoint.MarkerSize = 10; HighlightedPoint.MarkerShape = ScottPlot.MarkerShape.openCircle; HighlightedPoint.IsVisible = false; }
public System.Drawing.Bitmap Render(int width, int height) { Random rand = new Random(0); var mp = new MultiPlot(width: width, height: height, rows: 2, cols: 2); mp.GetSubplot(0, 0).PlotSignal(DataGen.Sin(50)); mp.GetSubplot(0, 1).PlotSignal(DataGen.Cos(50)); mp.GetSubplot(1, 0).PlotSignal(DataGen.Random(rand, 50)); mp.GetSubplot(1, 1).PlotSignal(DataGen.RandomWalk(rand, 50)); // adjust the bottom left plot to match the bottom right plot var plotToAdjust = mp.GetSubplot(1, 0); var plotReference = mp.GetSubplot(1, 1); plotToAdjust.SetAxisLimits(plotReference.GetAxisLimits()); plotToAdjust.MatchLayout(plotReference); return(mp.GetBitmap()); }
public void ExecuteRecipe(Plot plt) { Random rand = new(0); int pointCount = 30; double[] xs = DataGen.Consecutive(pointCount); double[] ys = DataGen.Random(rand, pointCount, 10); string[] labels = ys.Select(x => x.ToString("N2")).ToArray(); var labelFont = new Drawing.Font { Bold = true, Color = Color.Black, Alignment = Alignment.MiddleCenter }; var myBubblePlot = plt.AddBubblePlot(); for (int i = 0; i < xs.Length; i++) { // give each bubble a random size and make smaller ones bluer double randomValue = rand.NextDouble(); double bubbleSize = randomValue * 30 + 10; Color bubbleColor = Drawing.Colormap.Jet.GetColor(randomValue, .5); myBubblePlot.Add( x: xs[i], y: ys[i], radius: bubbleSize, fillColor: bubbleColor, edgeColor: Color.Transparent, edgeWidth: 1 ); plt.AddText(labels[i], xs[i], ys[i], labelFont); } plt.Title("Bubble Plot with Labels"); plt.AxisAuto(.2, .25); // zoom out to accommodate large bubbles }
private void PlotRandomData(object sender, RoutedEventArgs e) { wpfPlot1.Reset(); int pointCount = 5; Random rand = new Random(); double[] dataX = DataGen.Consecutive(pointCount); double[] dataY = DataGen.Random(rand, pointCount); string[] labels = { "One", "Two", "Three", "Four", "Five" }; wpfPlot1.Plot.AddScatter(dataX, dataY, label: "series 1"); wpfPlot1.Plot.Title("Plot Title"); wpfPlot1.Plot.XLabel("Horizontal Axis"); wpfPlot1.Plot.YLabel("Vertical Axis"); wpfPlot1.Plot.XTicks(dataX, labels); wpfPlot1.Plot.XAxis.TickLabelStyle(rotation: 90); wpfPlot1.Plot.AxisAuto(); wpfPlot1.Plot.Layout(left: 20, top: 50, bottom: 100, right: 20); wpfPlot1.Render(); }
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 ShowValueOnHover() { this.InitializeComponent(); #if DEBUG this.AttachDevTools(); #endif avaPlot1 = this.Find <AvaPlot>("avaPlot1"); // create a scatter plot from some random data and save it Random rand = new Random(0); int pointCount = 20; double[] xs = DataGen.Random(rand, pointCount); double[] ys = DataGen.Random(rand, pointCount, multiplier: 1_000); MyScatterPlot = avaPlot1.Plot.AddScatterPoints(xs, ys); // Add a red circle we can move around later as a highlighted point indicator HighlightedPoint = avaPlot1.Plot.AddPoint(0, 0); HighlightedPoint.Color = System.Drawing.Color.Red; HighlightedPoint.MarkerSize = 10; HighlightedPoint.MarkerShape = ScottPlot.MarkerShape.openCircle; HighlightedPoint.IsVisible = false; avaPlot1.PointerMoved += MouseMove; }
private void PlotRandomData(object sender, RoutedEventArgs e) { avaPlot1.Reset(); int pointCount = 5; Random rand = new Random(); double[] dataX = DataGen.Consecutive(pointCount); double[] dataY = DataGen.Random(rand, pointCount); string[] labels = { "One", "Two", "Three", "Four", "Five" }; avaPlot1.plt.PlotScatter(dataX, dataY, label: "series 1"); avaPlot1.plt.Title("Plot Title"); avaPlot1.plt.XLabel("Horizontal Axis"); avaPlot1.plt.YLabel("Vertical Axis"); avaPlot1.plt.XTicks(dataX, labels); avaPlot1.plt.Ticks(xTickRotation: 90); avaPlot1.plt.AxisAuto(); avaPlot1.plt.Layout(yLabelWidth: 20, titleHeight: 50, xLabelHeight: 50, y2LabelWidth: 20, xScaleHeight: 50); avaPlot1.Configure(recalculateLayoutOnMouseUp: false); avaPlot1.Render(); }
public void ExecuteRecipe(Plot plt) { // create random data and display it with a scatter plot double[] xs = DataGen.Consecutive(50); double[] ys = DataGen.Random(new Random(0), 50); plt.AddScatter(xs, ys, label: "data"); // add a draggable marker that "snaps" to data values in that scatter plot var dmpv = new ScottPlot.Plottable.DraggableMarkerPlotInVector() { Xs = xs, Ys = ys, DragEnabled = true, IsVisible = true, MarkerSize = 15, MarkerShape = MarkerShape.filledDiamond, MarkerColor = Color.Magenta, Label = "marker", }; plt.Add(dmpv); plt.Legend(); }
public void Render(Plot plt) { Random rand = new Random(0); plt.PlotErrorBars( xs: DataGen.Random(rand, 10, 10), ys: DataGen.Random(rand, 10, 10), xPositiveError: DataGen.Random(rand, 10), xNegativeError: DataGen.Random(rand, 10), yPositiveError: DataGen.Random(rand, 10), yNegativeError: DataGen.Random(rand, 10), label: "error bars" ); var func = new Func <double, double?>((x) => Math.Sin(x) * Math.Sin(10 * x) + 3); plt.PlotFunction(func, label: "function", lineWidth: 2); var func2 = new Func <double, double?>((x) => Math.Sin(x) * Math.Sin(10 * x) + 5); plt.PlotFunction(func2, label: null); // null labels will not appear in legend plt.PlotHLine(7.75, label: "horizontal line", lineStyle: LineStyle.Dot); plt.PlotVLine(7.75, label: "vertical line", lineStyle: LineStyle.Dash); plt.PlotHSpan(1.5, 2.5, label: "horizontal span"); plt.PlotVSpan(1.5, 2.5, label: "vertical span"); plt.PlotOHLC(new OHLC[] { new OHLC(5, 6, 4, 5.5, 1), new OHLC(6, 7.5, 3.5, 4.75, 1.5), new OHLC(5.5, 6, 3, 4.5, 2) }); plt.PlotCandlestick(new OHLC[] { new OHLC(5, 6, 4, 5.5, 3), new OHLC(6, 7.5, 3.5, 4.75, 3.5), new OHLC(5.5, 6, 3, 4.5, 4) }); plt.PlotScatter( xs: new double[] { 5, 5.5, 6, 7, 7, 6 }, ys: new double[] { 7, 8, 7, 9, 7, 8 }, lineStyle: LineStyle.Dash, lineWidth: 2, markerShape: MarkerShape.openCircle, markerSize: 10, label: "Scatter Plot" ); plt.PlotSignal( ys: DataGen.RandomNormal(rand, 10), sampleRate: 5, xOffset: 3, yOffset: 8, label: "Signal Plot" ); plt.PlotText("ScottPlot", 6, 6, rotation: 25, fontSize: 14, bold: true); plt.PlotPoint(1, 9, label: "point"); plt.PlotArrow(8, 8, 8.5, 8.5, label: "arrow"); plt.SetAxisLimits(0, 13, -1, 11); plt.Legend(); plt.Grid(false); }