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 mplt = new ScottPlot.MultiPlot(1000, 400, 1, 2); var pltDefault = mplt.GetSubplot(0, 0); pltDefault.Title("Default xSpacing"); pltDefault.PlotScatter(days, values); var pltTest = mplt.GetSubplot(0, 1); pltTest.Title("xSpacing = 1 unit"); pltTest.PlotScatter(days, values); // force inter-tick distance on a numerical axis pltTest.Grid(xSpacing: 1); TestTools.SaveFig(mplt); }
public void Test_MultiPlot_MatchJustOneAxis() { ScottPlot.MultiPlot multiplot = SampleMultiPlot(); multiplot.subplots[1].MatchAxis(multiplot.subplots[3], horizontal: false); multiplot.subplots[1].MatchLayout(multiplot.subplots[3], horizontal: false); multiplot.subplots[1].Title("#1 (matched vertical to #3)"); multiplot.subplots[2].MatchAxis(multiplot.subplots[3], vertical: false); multiplot.subplots[2].MatchLayout(multiplot.subplots[3], vertical: false); multiplot.subplots[2].Title("#2 (matched hoizontal to #3)"); string name = System.Reflection.MethodBase.GetCurrentMethod().Name; string filePath = System.IO.Path.GetFullPath(name + ".png"); multiplot.SaveFig(filePath); Console.WriteLine($"Saved {filePath}"); DisplayAxisInfo(multiplot); var matchedVerticalLimits = new ScottPlot.Config.AxisLimits2D(multiplot.subplots[1].Axis()); var matchedHorizontalLimits = new ScottPlot.Config.AxisLimits2D(multiplot.subplots[1].Axis()); Assert.That(matchedVerticalLimits.xSpan > 0 && matchedVerticalLimits.ySpan > 0); Assert.That(matchedHorizontalLimits.xSpan > 0 && matchedHorizontalLimits.ySpan > 0); }
private void DisplayAxisInfo(ScottPlot.MultiPlot multiplot) { for (int i = 0; i < multiplot.subplots.Length; i += 1) { var limits = new ScottPlot.Config.AxisLimits2D(multiplot.subplots[i].Axis()); Console.WriteLine($"Subplot index {i} {limits}"); } }
public void Test_MultiPlot_DefaultScales() { ScottPlot.MultiPlot multiplot = SampleMultiPlot(); string name = System.Reflection.MethodBase.GetCurrentMethod().Name; string filePath = System.IO.Path.GetFullPath(name + ".png"); multiplot.SaveFig(filePath); Console.WriteLine($"Saved {filePath}"); DisplayAxisInfo(multiplot); }
public static void SaveFig(ScottPlot.MultiPlot mplt, string subName = "") { var stackTrace = new System.Diagnostics.StackTrace(); string callingMethod = stackTrace.GetFrame(1).GetMethod().Name; string fileName = callingMethod + ".png"; string filePath = System.IO.Path.GetFullPath(fileName); mplt.SaveFig(filePath); Console.WriteLine($"Saved: {filePath}"); Console.WriteLine(); }
private ScottPlot.MultiPlot SampleMultiPlot() { var multiplot = new ScottPlot.MultiPlot(width: 800, height: 600, rows: 2, cols: 2); // plot an increasng spread of data in each subplot Random rand = new Random(0); int pointCount = 100; for (int i = 0; i < multiplot.subplots.Length; i += 1) { double zoom = Math.Pow(i + 1, 2); multiplot.subplots[i].Title($"#{i}"); multiplot.subplots[i].PlotScatter( xs: ScottPlot.DataGen.Random(rand, pointCount, multiplier: zoom, offset: -.5 * zoom), ys: ScottPlot.DataGen.Random(rand, pointCount, multiplier: zoom, offset: -.5 * zoom) ); } return(multiplot); }
public void Test_MultiPlot_MatchAxis() { ScottPlot.MultiPlot multiplot = SampleMultiPlot(); // update the lower left (index 2) plot to use the scale of the lower right (index 3) multiplot.subplots[2].MatchAxis(multiplot.subplots[3]); multiplot.subplots[2].Title("#2 (matched to #3)"); string name = System.Reflection.MethodBase.GetCurrentMethod().Name; string filePath = System.IO.Path.GetFullPath(name + ".png"); multiplot.SaveFig(filePath); Console.WriteLine($"Saved {filePath}"); DisplayAxisInfo(multiplot); var matchedAxisLimits = new ScottPlot.Config.AxisLimits2D(multiplot.subplots[2].Axis()); Assert.That(matchedAxisLimits.xSpan > 0 && matchedAxisLimits.ySpan > 0); }
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 mplt = new ScottPlot.MultiPlot(1000, 400, 1, 2); var pltDefault = mplt.GetSubplot(0, 0); pltDefault.Title("Default xSpacing"); pltDefault.PlotScatter(dates, values); pltDefault.Ticks(dateTimeX: true); var pltTest = mplt.GetSubplot(0, 1); pltTest.Title("xSpacing = 1 day"); pltTest.PlotScatter(dates, values); pltTest.Ticks(dateTimeX: true, xTickRotation: 45); pltTest.Layout(xScaleHeight: 60); // need extra height to accomodate rotated labels // force 1 tick per day on a DateTime axis pltTest.Grid(xSpacing: 1, xSpacingDateTimeUnit: ScottPlot.Config.DateTimeUnit.Day); TestTools.SaveFig(mplt); }
public void Test_Mel_VsFFT() { double[] audio = SampleData.SampleAudio1(); int sampleRate = 48_000; int melBinCount = 20; double[] fftMag = FftSharp.Transform.FFTmagnitude(audio); double[] fftMagMel = FftSharp.Transform.MelScale(fftMag, sampleRate, melBinCount); double fftFreqPeriod = FftSharp.Transform.FFTfreqPeriod(sampleRate, fftMag.Length); double maxMel = FftSharp.Transform.MelFromFreq(sampleRate / 2); var plt = new ScottPlot.MultiPlot(1000, 600, 2, 1); // TRADITIONAL SPECTROGRAM plt.subplots[0].PlotSignal(fftMag, 1.0 / fftFreqPeriod); for (int i = 0; i < melBinCount; i++) { double thisMel = (double)i / melBinCount * maxMel; double thisFreq = FftSharp.Transform.MelToFreq(thisMel); plt.subplots[0].PlotVLine(thisFreq, lineWidth: 2); } plt.subplots[0].YLabel("Power Spectral Density"); plt.subplots[0].XLabel("Frequency (Hz)"); plt.subplots[0].Title("Linear Frequency Scale"); // MEL SPECTROGRAM plt.subplots[1].PlotSignal(fftMagMel); for (int i = 0; i < melBinCount; i++) { plt.subplots[1].PlotVLine(i, lineWidth: 2); } plt.subplots[1].YLabel("Power Spectral Density"); plt.subplots[1].XLabel("Frequency (Mel)"); plt.subplots[1].Title("Mel Frequency Scale"); plt.SaveFig("audio-mel.png"); }
public static void Figure_EffectOfTemperature_SeveralSets() { /* this study calculates one of several known ionSets at every temperature between 0C and 50C */ var ionTable = new IonTable(); double[] temps = ScottPlot.DataGen.Consecutive(50); double[] jljpResults = new double[temps.Length]; double[] ngAndBarryResults = new double[temps.Length]; double[] HarperResults = new double[temps.Length]; double[] jpWinResults = new double[temps.Length]; List <Ion> ionSet; for (int i = 0; i < temps.Length; i++) { Console.WriteLine($"Calculating for {temps[i]}C..."); // see LjpCalculationTests.cs for ion set citations // create a new ion set for each iteration to prevent modifications due to solving from carrying to the next solve ionSet = new List <Ion> { new Ion("Zn", 9, 0.0284), new Ion("K", 0, 3), new Ion("Cl", 18, 3.0568) }; jljpResults[i] = Calculate.Ljp(ionTable.Lookup(ionSet), temps[i]).mV; ionSet = new List <Ion> { new Ion("Ca", 2, 2), new Ion("K", 100, 0), new Ion("Li", 0, 100), new Ion("Cl", 104, 104) }; ngAndBarryResults[i] = Calculate.Ljp(ionTable.Lookup(ionSet), temps[i]).mV; ionSet = new List <Ion> { new Ion("Ca", .29, .00545), new Ion("Cl", .29 * 2, .00545 * 2) }; HarperResults[i] = Calculate.Ljp(ionTable.Lookup(ionSet), temps[i]).mV; ionSet = new List <Ion> { new Ion("Na", 10, 145), new Ion("Cl", 10, 145), new Ion("Cs", 135, 0), new Ion("F", 135, 0) }; jpWinResults[i] = Calculate.Ljp(ionTable.Lookup(ionSet), temps[i]).mV; } var mplt = new ScottPlot.MultiPlot(800, 600, 2, 2); mplt.subplots[0].PlotScatter(temps, jljpResults); mplt.subplots[0].Title("JLJP screenshot"); mplt.subplots[1].PlotScatter(temps, ngAndBarryResults); mplt.subplots[1].Title("Ng and Barry (1994)"); mplt.subplots[2].PlotScatter(temps, HarperResults); mplt.subplots[2].Title("Harper (1985)"); mplt.subplots[3].PlotScatter(temps, jpWinResults); mplt.subplots[3].Title("JPWin screenshot"); for (int i = 0; i < 4; i++) { mplt.subplots[i].YLabel("LJP (mV)"); mplt.subplots[i].XLabel("Temperature (C)"); } string filePath = System.IO.Path.GetFullPath("Figure_EffectOfTemperature.png"); mplt.SaveFig(filePath); Console.WriteLine($"Saved: {filePath}"); }