Exemple #1
0
        public void Test_NaturalSpline_ValuesMatch()
        {
            double[] xs = { 0, 10, 20, 30 };
            double[] ys = { 65, 25, 55, 80 };

            var nsi = new ScottPlot.Statistics.Interpolation.NaturalSpline(xs, ys, resolution: 20);
            var psi = new ScottPlot.Statistics.Interpolation.PeriodicSpline(xs, ys, resolution: 20);
            var esi = new ScottPlot.Statistics.Interpolation.EndSlopeSpline(xs, ys, resolution: 20);

            // verify output values have not deviated frrom what is expected
            Assert.AreEqual(-1752748231, ScottPlot.Tools.SimpleHash(nsi.interpolatedXs));
            Assert.AreEqual(-1060440570, ScottPlot.Tools.SimpleHash(nsi.interpolatedYs));
            Assert.AreEqual(-1752748231, ScottPlot.Tools.SimpleHash(psi.interpolatedXs));
            Assert.AreEqual(-351909896, ScottPlot.Tools.SimpleHash(psi.interpolatedYs));
            Assert.AreEqual(-1752748231, ScottPlot.Tools.SimpleHash(esi.interpolatedXs));
            Assert.AreEqual(-2040768015, ScottPlot.Tools.SimpleHash(esi.interpolatedYs));

            var plt = new ScottPlot.Plot();

            plt.PlotScatter(xs, ys, Color.Black, markerSize: 10, lineWidth: 0, label: "Original Data");
            plt.PlotScatter(nsi.interpolatedXs, nsi.interpolatedYs, Color.Red, markerSize: 3, label: "Natural Spline");
            plt.PlotScatter(psi.interpolatedXs, psi.interpolatedYs, Color.Green, markerSize: 3, label: "Periodic Spline");
            plt.PlotScatter(esi.interpolatedXs, esi.interpolatedYs, Color.Blue, markerSize: 3, label: "End Slope Spline");
            plt.Legend();
            TestTools.SaveFig(plt);
        }
Exemple #2
0
        public void ExecuteRecipe(Plot plt)
        {
            // create a small number of X/Y data points and display them
            double[] xs = { 0, 10, 20, 30 };
            double[] ys = { 65, 25, 55, 80 };
            plt.AddScatter(xs, ys, Color.Black, markerSize: 10, lineWidth: 0, label: "Original Data");

            // Calculate the interpolated splines using three different methods:
            //   Natural splines are "stiffer" than a polynomial interpolations and are less likely to oscillate.
            //   Periodic splines are natural splines whose first and last point slopes are matched.
            //   End slope splines let you define first and last data point slopes (defaults to zero).
            var nsi = new ScottPlot.Statistics.Interpolation.NaturalSpline(xs, ys, resolution: 20);
            var psi = new ScottPlot.Statistics.Interpolation.PeriodicSpline(xs, ys, resolution: 20);
            var esi = new ScottPlot.Statistics.Interpolation.EndSlopeSpline(xs, ys, resolution: 20);

            // plot the interpolated Xs and Ys
            plt.AddScatter(nsi.interpolatedXs, nsi.interpolatedYs, Color.Red, markerSize: 3, label: "Natural Spline");
            plt.AddScatter(psi.interpolatedXs, psi.interpolatedYs, Color.Green, markerSize: 3, label: "Periodic Spline");
            plt.AddScatter(esi.interpolatedXs, esi.interpolatedYs, Color.Blue, markerSize: 3, label: "End Slope Spline");

            plt.Legend();
        }
Exemple #3
0
        private void Replot()
        {
            formsPlot1.plt.Clear();

            double[] xs      = { 0, 51, 102, 153, 204, 255 };
            double[] redYs   = { tbRed1.Value, tbRed2.Value, tbRed3.Value, tbRed4.Value, tbRed5.Value, tbRed6.Value };
            double[] greenYs = { tbGreen1.Value, tbGreen2.Value, tbGreen3.Value, tbGreen4.Value, tbGreen5.Value, tbGreen6.Value };
            double[] blueYs  = { tbBlue1.Value, tbBlue2.Value, tbBlue3.Value, tbBlue4.Value, tbBlue5.Value, tbBlue6.Value };

            int resolution  = 51;
            var redInterp   = new ScottPlot.Statistics.Interpolation.NaturalSpline(xs, redYs, resolution);
            var greenInterp = new ScottPlot.Statistics.Interpolation.NaturalSpline(xs, greenYs, resolution);
            var blueInterp  = new ScottPlot.Statistics.Interpolation.NaturalSpline(xs, blueYs, resolution);

            double[] xsCurve    = redInterp.interpolatedXs;
            double[] redCurve   = redInterp.interpolatedYs;
            double[] greenCurve = greenInterp.interpolatedYs;
            double[] blueCurve  = blueInterp.interpolatedYs;

            double[] meanCurve = new double[redCurve.Length];
            for (int i = 0; i < 256; i++)
            {
                byte   redByte   = (byte)Math.Max(Math.Min(redCurve[i], 255), 0);
                byte   greenByte = (byte)Math.Max(Math.Min(greenCurve[i], 255), 0);
                byte   blueByte  = (byte)Math.Max(Math.Min(blueCurve[i], 255), 0);
                byte   alphaByte = 255;
                byte[] bytes     = { blueByte, greenByte, redByte, alphaByte };
                colormap[i]  = BitConverter.ToInt32(bytes, 0);
                meanCurve[i] = (redByte + greenByte + blueByte) / 3.0;
            }

            formsPlot1.plt.PlotScatter(xs, redYs, Color.Red, 0);
            formsPlot1.plt.PlotScatter(xs, greenYs, Color.Green, 0);
            formsPlot1.plt.PlotScatter(xs, blueYs, Color.Blue, 0);

            formsPlot1.plt.PlotScatter(xsCurve, redCurve, color: Color.Red, markerSize: 0);
            formsPlot1.plt.PlotScatter(xsCurve, greenCurve, color: Color.Green, markerSize: 0);
            formsPlot1.plt.PlotScatter(xsCurve, blueCurve, color: Color.Blue, markerSize: 0);
            formsPlot1.plt.PlotScatter(xsCurve, meanCurve, color: Color.Black, markerSize: 0, lineStyle: ScottPlot.LineStyle.Dash);

            //formsPlot1.plt.Frame(false);
            //formsPlot1.plt.Ticks(false, false);
            //formsPlot1.plt.Axis(0, 255, 0, 255);
            formsPlot1.plt.PlotVLine(0, Color.Black, lineStyle: ScottPlot.LineStyle.Dot);
            formsPlot1.plt.PlotVLine(255, Color.Black, lineStyle: ScottPlot.LineStyle.Dot);
            formsPlot1.plt.PlotHLine(0, Color.Black, lineStyle: ScottPlot.LineStyle.Dot);
            formsPlot1.plt.PlotHLine(255, Color.Black, lineStyle: ScottPlot.LineStyle.Dot);
            formsPlot1.Render();

            Size   cmapSize = pbColorbar.Size;
            Bitmap bmp      = new Bitmap(cmapSize.Width, cmapSize.Height);

            using (var gfx = Graphics.FromImage(bmp))
                using (var pen = new Pen(Color.White))
                {
                    for (int x = 0; x < cmapSize.Width; x++)
                    {
                        double intensityFrac  = (double)x / cmapSize.Width;
                        int    intensityValue = (int)(255.0 * intensityFrac);
                        pen.Color = Color.FromArgb(colormap[intensityValue]);
                        gfx.DrawLine(pen, x, 0, x, cmapSize.Height);
                    }
                }

            pbColorbar.Image?.Dispose();
            pbColorbar.Image = bmp;
            newValues        = true;
        }
Exemple #4
0
        public static void UpdatePlot(FormsPlot formsPlot, string title, int chamberNum
                                      , Dictionary <string, List <double> > chDataDic
                                      , CheckBox cBoxFAM, CheckBox cBoxROX, CheckBox cBoxHEX, CheckBox cBoxCYS, double Ct_FAM, double Ct_ROX, double Ct_HEX, double Ct_CY5)
        {
            labelTicks = new List <string>();
            formsPlot.plt.Clear();

            //formsPlot.Configure(enablePanning: false, enableZooming: false);
            //vLine = formsPlot1.plt.PlotVLine(0, color: Color.Red, lineStyle: LineStyle.Dash);
            //hLine = formsPlot1.plt.PlotHLine(0, color: Color.Red, lineStyle: LineStyle.Dash);

            var dataXList = new List <double>();

            //for (int i = 0; i < 30; i++)
            for (int i = 0; i < chDataDic["FAM"].Count; i++)
            {
                dataXList.Add(i);
            }

            if (chDataDic["FAM"].Count > 0)
            {
                chFAMArray[chamberNum]         = formsPlot.plt.PlotScatter(dataXList.ToArray(), chDataDic["FAM"].ToArray(), label: "FAM", lineWidth: 0); //ROX, HEX, CYS
                chFAMArray[chamberNum].visible = chFAMIsCheck[chamberNum];
            }
            if (chDataDic["ROX"].Count > 0)
            {
                chROXArray[chamberNum]         = formsPlot.plt.PlotScatter(dataXList.ToArray(), chDataDic["ROX"].ToArray(), label: "ROX", lineWidth: 0); //ROX, HEX, CYS
                chROXArray[chamberNum].visible = chROXIsCheck[chamberNum];
            }
            if (chDataDic["HEX"].Count > 0)
            {
                chHEXArray[chamberNum]         = formsPlot.plt.PlotScatter(dataXList.ToArray(), chDataDic["HEX"].ToArray(), label: "HEX", lineWidth: 0); //ROX, HEX, CYS
                chHEXArray[chamberNum].visible = chHEXIsCheck[chamberNum];
            }
            if (chDataDic["CY5"].Count > 0)
            {
                chCY5Array[chamberNum]         = formsPlot.plt.PlotScatter(dataXList.ToArray(), chDataDic["CY5"].ToArray(), label: "CY5", lineWidth: 0); //ROX, HEX, CYS
                chCY5Array[chamberNum].visible = chCY5IsCheck[chamberNum];
            }

            if (chDataDic["FAM"].Count > 3)
            {
                var nsi = new ScottPlot.Statistics.Interpolation
                          .NaturalSpline(dataXList.ToArray(), chDataDic["FAM"].ToArray(), resolution: 20);
                chFAMHLArray[chamberNum] = formsPlot.plt.PlotScatterHighlight(nsi.interpolatedXs, nsi.interpolatedYs
                                                                              , Color.Blue, markerSize: 0);

                chFAMHLArray[chamberNum].visible = chFAMHLIsCheck[chamberNum];
            }

            if (chDataDic["ROX"].Count > 3)
            {
                var nsi = new ScottPlot.Statistics.Interpolation
                          .NaturalSpline(dataXList.ToArray(), chDataDic["ROX"].ToArray(), resolution: 20);
                chROXHLArray[chamberNum] = formsPlot.plt.PlotScatterHighlight(nsi.interpolatedXs, nsi.interpolatedYs
                                                                              , Color.Orange, markerSize: 0);
                chROXHLArray[chamberNum].visible = chROXHLIsCheck[chamberNum];
            }
            if (chDataDic["HEX"].Count > 3)
            {
                var nsi = new ScottPlot.Statistics.Interpolation
                          .NaturalSpline(dataXList.ToArray(), chDataDic["HEX"].ToArray(), resolution: 20);
                chHEXHLArray[chamberNum] = formsPlot.plt.PlotScatterHighlight(nsi.interpolatedXs, nsi.interpolatedYs
                                                                              , Color.Green, markerSize: 0);
                chHEXHLArray[chamberNum].visible = chHEXHLIsCheck[chamberNum];
            }

            if (chDataDic["CY5"].Count > 3)
            {
                var nsi = new ScottPlot.Statistics.Interpolation
                          .NaturalSpline(dataXList.ToArray(), chDataDic["CY5"].ToArray(), resolution: 20);
                chCY5HLArray[chamberNum] = formsPlot.plt.PlotScatterHighlight(nsi.interpolatedXs, nsi.interpolatedYs
                                                                              , Color.Red, markerSize: 0);
                chCY5HLArray[chamberNum].visible = chCY5HLIsCheck[chamberNum];
            }
            //formsPlot.plt.AxisAutoX(expandOnly: true);
            for (int i = 0; i < dataXList.Count; i++)
            {
                if (i < COL_CNT)
                {
                    labelTicksArray[i] = Optic_Measure_Idx[i].ToString();
                }
                labelTicks.Add(labelTicksArray[i]);
            }

            //for (int i = 0; i < dataXList.Count; i++)

            formsPlot.plt.XTicks(dataXList.ToArray(), labelTicks.ToArray());
            formsPlot.plt.Title(title);
            formsPlot.plt.Legend(location: legendLocation.upperLeft);
            formsPlot.plt.Axis(0, COL_CNT - 1, 0, 3000);
            formsPlot.plt.Layout(xLabelHeight: 40);
            formsPlot.Configure(recalculateLayoutOnMouseUp: false);

            formsPlot.plt.PlotHLine(y: Ct_FAM, label: "FAM baseline");
            formsPlot.plt.PlotHLine(y: Ct_ROX, label: "ROX baseline");
            formsPlot.plt.PlotHLine(y: Ct_HEX, label: "HEX baseline");
            formsPlot.plt.PlotHLine(y: Ct_CY5, label: "CY5 baseline");
            //formsPlot.plt.TightenLayout(padding: 40);
            formsPlot.Render();
        }