Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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");
        }
Exemplo n.º 3
0
        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}");
        }