public void Test_AutoAxis_ShrinkWhenNeeded() { Random rand = new Random(0); var plt = new ScottPlot.Plot(); // small area plt.PlotLine(-5, -5, 5, 5); plt.AxisAuto(); var limitsA = new ScottPlot.Config.AxisLimits2D(plt.Axis()); Console.WriteLine($"limits A: {limitsA}"); // expand to large area plt.Axis(-123, 123, -123, 123); var limitsB = new ScottPlot.Config.AxisLimits2D(plt.Axis()); Console.WriteLine($"limits B: {limitsB}"); // shrink back to small area plt.AxisAuto(); var limitsC = new ScottPlot.Config.AxisLimits2D(plt.Axis()); Console.WriteLine($"limits C: {limitsC}"); Assert.That(limitsB.xSpan > limitsC.xSpan); Assert.That(limitsB.ySpan > limitsC.ySpan); Assert.That(limitsA.xSpan == limitsC.xSpan); Assert.That(limitsA.ySpan == limitsC.ySpan); }
public string Figure_66_CPH() { string name = System.Reflection.MethodBase.GetCurrentMethod().Name.Replace("Figure_", ""); string fileName = System.IO.Path.GetFullPath($"{outputFolderName}/{name}.png"); Random rand = new Random(0); double[] values1 = ScottPlot.DataGen.RandomNormal(rand, pointCount: 1000, mean: 50, stdDev: 20); double[] values2 = ScottPlot.DataGen.RandomNormal(rand, pointCount: 1000, mean: 45, stdDev: 25); var hist1 = new ScottPlot.Histogram(values1, min: 0, max: 100); var hist2 = new ScottPlot.Histogram(values2, min: 0, max: 100); var plt = new ScottPlot.Plot(width, height); plt.Title("Cumulative Probability Histogram"); plt.YLabel("Probability (fraction)"); plt.XLabel("Value (units)"); plt.PlotStep(hist1.bins, hist1.cumulativeFrac, lineWidth: 1.5, label: "sample A"); plt.PlotStep(hist2.bins, hist2.cumulativeFrac, lineWidth: 1.5, label: "sample B"); plt.Legend(); plt.Axis(null, null, 0, 1); plt.SaveFig(fileName); Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}"); return(name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap())); }
public void Test_PlottableBar2_MultiSeries() { double[,] values = new double[, ] { { 15, 22, 45, 17 }, { 37, 21, 29, 13 } }; string[] rowLabels = new string[] { "men", "women" }; string[] colLabels = new string[] { "always", "regularly", "sometimes", "never" }; Assert.AreEqual(values.GetLength(0), rowLabels.Length); Assert.AreEqual(values.GetLength(1), colLabels.Length); var plt = new ScottPlot.Plot(400, 300); // create and add an experimental plottable (not in the ScottPlot namespace) var pltBar = new PlottableBar2(rowLabels, colLabels, values); plt.Add(pltBar); plt.Title("How often do you read reviews?"); plt.XTicks(colLabels); plt.Ticks(useMultiplierNotation: false); plt.Axis(-1, colLabels.Length, 0, null); plt.Grid(enableVertical: false); TestTools.SaveFig(plt); }
public void Test_PlottableBar2_SingleSeries() { double[,] values = new double[, ] { { 7, 12, 40, 40, 100, 125, 172, 550, 560, 600, 2496, 2789 } }; string[] rowLabels = new string[] { null }; string[] colLabels = new string[] { "ant", "bird", "mouse", "human", "cat", "dog", "frog", "lion", "elephant", "horse", "shark", "hippo" }; Assert.AreEqual(values.GetLength(0), rowLabels.Length); Assert.AreEqual(values.GetLength(1), colLabels.Length); var plt = new ScottPlot.Plot(400, 300); // create and add an experimental plottable (not in the ScottPlot namespace) var pltBar = new PlottableBar2(rowLabels, colLabels, values); plt.Add(pltBar); plt.Title("Body-to-Brain Mass Ratio"); plt.XTicks(colLabels); plt.Axis(-1, colLabels.Length, 0, null); plt.Grid(enableVertical: false); // customize ticks to display better at high density plt.Ticks(useMultiplierNotation: false); plt.Ticks(xTickRotation: 45); plt.Layout(xLabelHeight: 40); TestTools.SaveFig(plt); }
static void DisplayTicks(double low, double high) { var plt = new ScottPlot.Plot(); plt.Axis(low, high); var ticks = new ScottPlot.TickCollection(plt.GetSettings()); Console.WriteLine(ticks); }
public void Test_AutoAxis_ExpandYonly() { Random rand = new Random(0); var plt = new ScottPlot.Plot(); // small area plt.PlotLine(-5, -5, 5, 5); plt.AxisAuto(); var limitsA = new ScottPlot.Config.AxisLimits2D(plt.Axis()); // large area plt.PlotLine(-99, -99, 99, 99); plt.AxisAuto(yExpandOnly: true); var limitsB = new ScottPlot.Config.AxisLimits2D(plt.Axis()); Assert.That(limitsA.xSpan == limitsB.xSpan); Assert.That(limitsA.ySpan < limitsB.ySpan); }
public void Test_SignalXY_RenderLimits() { Random rand = new Random(0); double[] xs = ScottPlot.DataGen.Consecutive(100_000); double[] ys = ScottPlot.DataGen.RandomWalk(rand, 100_000); var plt = new ScottPlot.Plot(500, 350); plt.PlotSignalXY(xs, ys, minRenderIndex: 4000, maxRenderIndex: 5000); plt.Axis(y1: -200, y2: 200); TestTools.SaveFig(plt); }
/// <summary> /// Initialize <see cref="ScottPlot.Plot"/> object. /// </summary> /// <param name="formsPlot">Where to fit the fig to.</param> /// <param name="labelTitle">Fig label.</param> /// <param name="labelX">X axis label.</param> /// <param name="labelY">Y axis label.</param> /// <returns></returns> private ScottPlot.Plot PlotInitialize(ScottPlot.FormsPlot formsPlot, string labelTitle, string labelX, string labelY) { ScottPlot.Plot plt = formsPlot.plt; plt.Grid(enable: false); plt.Style(figBg: Color.Transparent, dataBg: Color.White); plt.Title(labelTitle); plt.XLabel(labelX); plt.YLabel(labelY); plt.Axis(null, null, 0, null); formsPlot.Render(); return(plt); }
public void Figure_01c_Defined_Axis_Limits() { string name = System.Reflection.MethodBase.GetCurrentMethod().Name.Replace("Figure_", ""); string fileName = System.IO.Path.GetFullPath($"{outputFolderName}/{name}.png"); var plt = new ScottPlot.Plot(width, height); plt.PlotScatter(dataXs, dataSin); plt.PlotScatter(dataXs, dataCos); plt.Axis(2, 8, .2, 1.1); // x1, x2, y1, y2 plt.SaveFig(fileName); Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}"); }
public void Test_AutoAxis_WorksAfterClear() { var plt = new ScottPlot.Plot(); plt.PlotPoint(0.1, 0.1); plt.PlotPoint(-0.1, -0.1); plt.AxisAuto(); plt.GetBitmap(); // force a render Assert.Greater(plt.Axis()[0], -5); plt.PlotPoint(999, 999); plt.PlotPoint(-999, -999); plt.AxisAuto(); plt.GetBitmap(); // force a render Assert.Less(plt.Axis()[0], -800); plt.Clear(); plt.PlotPoint(0.1, 0.1); plt.PlotPoint(-0.1, -0.1); plt.GetBitmap(); // force a render Assert.Greater(plt.Axis()[0], -5); }
public void Test_DataContainsNan_Scatter() { double[] xs = new double[] { 1, double.NaN, 3, 4, 5, 6 }; double[] ys = new double[] { 1, 4, 9, 16, double.NaN, 36 }; var plt = new ScottPlot.Plot(); plt.PlotScatter(xs, ys); plt.AxisAuto(); var ax = plt.Axis(); Console.WriteLine($"Automatic axis limits: x1={ax[0]}, x2={ax[0]}, y1={ax[0]}, y2={ax[0]}"); plt.Axis(-2, 7, -10, 40); string name = System.Reflection.MethodBase.GetCurrentMethod().Name; string filePath = System.IO.Path.GetFullPath(name + ".png"); plt.SaveFig(filePath); Console.WriteLine($"Saved {filePath}"); }
public void Test_PlotTicks_OffsetNotation() { var plt = new ScottPlot.Plot(); plt.Axis(1e10, 1e10 + 10, 1e10, 1e10 + 10); plt.XLabel("Horizontal Axis Label"); plt.YLabel("Vertical Axis Label"); var before = new MeanPixel(plt); plt.Ticks(useOffsetNotation: true); var after = new MeanPixel(plt); TestTools.SaveFig(plt); Assert.That(after.IsDifferentThan(before)); }
public void Test_Filter_BandStop() { double[] Filtered = FftSharp.Filter.BandStop(Values, SampleRate, 1900, 2100); var plt = new ScottPlot.Plot(600, 400); plt.PlotScatter(TimesMsec, Values, label: "Original"); plt.PlotScatter(TimesMsec, Filtered, label: "Band-Pass", lineWidth: 2); plt.YLabel("Signal Value"); plt.XLabel("Time (milliseconds)"); plt.Legend(); plt.Axis(x1: 4, x2: 6); TestTools.SaveFig(plt); }
public void Test_PlotTicks_ExponentialNotation() { var plt = new ScottPlot.Plot(); plt.Axis(-1e10, 1e10, -1e10, 1e10); plt.XLabel("Horizontal Axis Label"); plt.YLabel("Vertical Axis Label"); plt.Ticks(useMultiplierNotation: true); var before = new MeanPixel(plt); plt.Ticks(useExponentialNotation: false); var after = new MeanPixel(plt); TestTools.SaveFig(plt); Assert.That(after.IsDifferentThan(before)); }
public void Test_Bar_ShowValuesHorizontal() { double[] xs = { 1, 2, 3, 4, 5 }; double[] ys1 = { 10, 15, 12, 6, 8, }; double[] ys2 = { 6, 8, 8, 9, 5 }; var plt = new ScottPlot.Plot(400, 300); plt.PlotBar(xs, ys1, xOffset: -.20, barWidth: 0.3, showValues: true, label: "Series A", horizontal: true); plt.PlotBar(xs, ys2, xOffset: +.20, barWidth: 0.3, showValues: true, label: "Series B", horizontal: true); plt.Grid(lineStyle: ScottPlot.LineStyle.Dot, enableVertical: false); plt.Legend(location: ScottPlot.legendLocation.upperRight); plt.Axis(x1: 0); TestTools.SaveFig(plt); }
public void Test_OHLC_SetWidth() { var ohlcs = new ScottPlot.OHLC[] { // open, high, low, close, time, timeSpan new ScottPlot.OHLC(273, 275, 264, 265, 1, 1), new ScottPlot.OHLC(267, 276, 265, 274, 2.5, 2), new ScottPlot.OHLC(277, 280, 275, 278, 4, 1), }; var plt = new ScottPlot.Plot(400, 300); plt.Grid(false); plt.PlotOHLC(ohlcs, autoWidth: false); plt.Axis(-1, 5); TestTools.SaveFig(plt); }
public void Test_AxisAutoX_Repeated() { double[] xs = { 1, 2, 3, 4, 5 }; double[] ys = { 1, 4, 9, 16, 25 }; var plt = new ScottPlot.Plot(400, 300); plt.PlotScatter(xs, ys); plt.Axis(-5, 10, -15, 40); for (int i = 0; i < 10; i++) { plt.AxisAutoX(); } TestTools.SaveFig(plt); }
public void Test_PlotTicks_DateTime() { var plt = new ScottPlot.Plot(); DateTime dt1 = new DateTime(2020, 1, 1); DateTime dt2 = new DateTime(2020, 12, 25); plt.Axis(dt1.ToOADate(), dt2.ToOADate(), dt1.ToOADate(), dt2.ToOADate()); plt.XLabel("Horizontal Axis Label"); plt.YLabel("Vertical Axis Label"); var before = new MeanPixel(plt); plt.Ticks(dateTimeX: true, dateTimeY: true); var after = new MeanPixel(plt); TestTools.SaveFig(plt); Assert.That(after.IsDifferentThan(before)); }
public void Test_Candle_CustomColors() { var ohlcs = new ScottPlot.OHLC[] { // open, high, low, close, time, timeSpan new ScottPlot.OHLC(273, 275, 264, 265, 1, 1), new ScottPlot.OHLC(267, 276, 265, 274, 2.5, 2), new ScottPlot.OHLC(277, 280, 275, 278, 4, 1), }; var colorUp = System.Drawing.ColorTranslator.FromHtml("#9926a69a"); var colorDown = System.Drawing.ColorTranslator.FromHtml("#99ef5350"); var plt = new ScottPlot.Plot(400, 300); plt.PlotCandlestick(ohlcs, colorUp, colorDown, autoWidth: false); plt.Axis(-1, 5); TestTools.SaveFig(plt); }
public void Test_AscendingUnevenlySpacedXs_ShouldRenderWell() { // generate random, ascending, unevenly-spaced data Random rand = new Random(0); int pointCount = 100_000; double[] ys = new double[pointCount]; double[] xs = new double[pointCount]; for (int i = 1; i < ys.Length; i++) { ys[i] = ys[i - 1] + rand.NextDouble() - .5; xs[i] = xs[i - 1] + rand.NextDouble(); } var plt = new ScottPlot.Plot(500, 350); plt.PlotSignalXY(xs, ys); plt.Axis(20530, 20560, -61, -57); TestTools.SaveFig(plt); }
public void TestGroup_Axes() { Console.Write($"Axis adjustments (auto, pan, zoom) ... "); plt.Clear(); plt.PlotScatter(xs, ys); plt.AxisAuto(); double[] axesBefore = new double[4]; Array.Copy(plt.Axis(), axesBefore, 4); plt.Axis(-1, 1, -1, 1); Debug.Assert(axesAreDifferent(axesBefore, plt.Axis())); plt.AxisAuto(); Debug.Assert(!axesAreDifferent(axesBefore, plt.Axis())); plt.AxisPan(1, 2); Debug.Assert(axesAreDifferent(axesBefore, plt.Axis())); plt.AxisAuto(); Debug.Assert(!axesAreDifferent(axesBefore, plt.Axis())); plt.AxisZoom(2, 3); Debug.Assert(axesAreDifferent(axesBefore, plt.Axis())); plt.AxisAuto(); Debug.Assert(!axesAreDifferent(axesBefore, plt.Axis())); Pass(); }
/// <summary> /// The left plot is mainly used for spectra. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="fitGraphics">Skip by null or /// <see cref="SpectraProcessor.FitGraphics.Empty"/></param> /// <param name="xLabel">Fill null >> default from <see cref="Constants"/>.</param> /// <param name="yLabel">Fill null >> default from <see cref="Constants"/>.</param> private void PlotLeft(double[] x, double[] y, SpectraProcessor.FitGraphics fitGraphics, string xLabel = null, string yLabel = null) { if (plotLeft == null) { return; } if (x.Length != y.Length) { return; } plotLeft.XLabel(xLabel ?? constants.PlotLeft_XLabel); plotLeft.YLabel(yLabel ?? constants.PlotLeft_YLabel); plotLeft.AxisAuto(horizontalMargin: .9, verticalMargin: .5); plotLeft.Axis(null, null, 0, null); plotLeft.Clear(); plotLeft.PlotScatter(x, y, markerSize: 0, color: Color.Red, lineWidth: 0.1); if (!SpectraProcessor.FitGraphics.IsNullOrEmpty(fitGraphics)) { // Plot fit lines and crossing point. plotLeft.PlotScatter(fitGraphics.LeftLineXs, fitGraphics.LeftLineYs, markerSize: 0, color: Color.Black); plotLeft.PlotScatter(fitGraphics.RightLineXs, fitGraphics.RightLineYs, markerSize: 0, color: Color.Black); plotLeft.PlotPoint(fitGraphics.Intersection.X, fitGraphics.Intersection.Y, markerSize: 5, color: Color.Blue); // Mark points where fitting occured. double[] xFit, yFit; // Left line. (xFit, yFit) = fitGraphics.MarkedPlotLeft(x, y); plotLeft.PlotScatter(xFit, yFit, markerSize: 3, color: Color.Black, lineWidth: 0); // Right line. (xFit, yFit) = fitGraphics.MarkedPlotRight(x, y); plotLeft.PlotScatter(xFit, yFit, markerSize: 3, color: Color.Black, lineWidth: 0); } formsPlotLeft.Render(); }
public string Figure_65_Histogram() { string name = System.Reflection.MethodBase.GetCurrentMethod().Name.Replace("Figure_", ""); string fileName = System.IO.Path.GetFullPath($"{outputFolderName}/{name}.png"); Random rand = new Random(0); double[] values1 = ScottPlot.DataGen.RandomNormal(rand, pointCount: 1000, mean: 50, stdDev: 20); var hist1 = new ScottPlot.Histogram(values1, min: 0, max: 100); var plt = new ScottPlot.Plot(width, height); plt.Title("Histogram"); plt.YLabel("Count (#)"); plt.XLabel("Value (units)"); plt.PlotBar(hist1.bins, hist1.counts, barWidth: 1); plt.Axis(null, null, 0, null); plt.SaveFig(fileName); Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}"); return(name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap())); }
public void Test_Bar_Stacked() { double[] xs = { 1, 2, 3, 4, 5 }; double[] valuesA = { 1, 2, 3, 2, 1, }; double[] valuesB = { 3, 3, 2, 1, 3 }; // to simulate stacking, 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]; } var plt = new ScottPlot.Plot(400, 300); plt.PlotBar(xs, valuesB2, label: "Series B"); // plot the uppermost bar first plt.PlotBar(xs, valuesA, label: "Series A"); // plot lower bars last (in front) plt.Legend(location: ScottPlot.legendLocation.upperRight); plt.Axis(y2: 7); plt.Title("Stacked Bar Charts"); TestTools.SaveFig(plt); }
public string Figure_62_Plot_Bar_Data_Fancy() { string name = System.Reflection.MethodBase.GetCurrentMethod().Name.Replace("Figure_", ""); string fileName = System.IO.Path.GetFullPath($"{outputFolderName}/{name}.png"); // generate some more complex data Random rand = new Random(0); int pointCount = 10; double[] Xs = new double[pointCount]; double[] dataA = new double[pointCount]; double[] errorA = new double[pointCount]; double[] XsB = new double[pointCount]; double[] dataB = new double[pointCount]; double[] errorB = new double[pointCount]; for (int i = 0; i < pointCount; i++) { Xs[i] = i * 10; dataA[i] = rand.NextDouble() * 100; dataB[i] = rand.NextDouble() * 100; errorA[i] = rand.NextDouble() * 10; errorB[i] = rand.NextDouble() * 10; } var plt = new ScottPlot.Plot(width, height); plt.Title("Multiple Bar Plots"); plt.Grid(false); // we customize barWidth and xOffset to squeeze grouped bars together plt.PlotBar(Xs, dataA, errorY: errorA, label: "data A", barWidth: 3.2, xOffset: -2); plt.PlotBar(Xs, dataB, errorY: errorB, label: "data B", barWidth: 3.2, xOffset: 2); plt.Axis(null, null, 0, null); plt.Legend(); plt.SaveFig(fileName); Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}"); return(name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap())); }
/// <summary> /// The right plot is mainly used for temperature history. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="xLabel">Fill null >> default from <see cref="Constants"/>.</param> /// <param name="yLabel">Fill null >> default from <see cref="Constants"/>.</param> private void PlotRight(double[] x, double[] y, string xLabel = null, string yLabel = null) { if (plotRight == null) { return; } double length; if (x.Length == y.Length) { length = x.Length; } else { return; } if (length > 0) { double?timesMin, timesMax, temperaturesMin, temperaturesMax; // Axis limits. if (length == 1) { timesMin = x[0] - 1; timesMax = x[0] + 1; temperaturesMin = y.Min() - 1; temperaturesMax = y.Max() + 1; } else { timesMin = timesMax = temperaturesMin = temperaturesMax = null; bool timesEqual = x.Min() == x.Max(); bool temperaturesEqual = y.Min() == y.Max(); if (timesEqual) { timesMin = x.Min() - 1; timesMax = x.Max() + 1; } if (temperaturesEqual) { temperaturesMin = y.Min() - 1; temperaturesMax = y.Max() + 1; } if (!(timesEqual || temperaturesEqual)) // Main case. { plotRight.AxisAuto(.9, .5); if (x.Min() >= 0) { timesMin = 0d; } ; } } plotRight.Axis(timesMin, timesMax, temperaturesMin, temperaturesMax); plotRight.XLabel(xLabel ?? constants.PlotRight_XLabel); plotRight.YLabel(yLabel ?? constants.PlotRight_YLabel); plotRight.Clear(); plotRight.PlotScatter(x, y, color: Color.Red); } formsPlotRight.Render(); }