Esempio n. 1
0
 public void ClearPlot()
 {
     Console.Write($"Clearing plot of all data elements ... ");
     Debug.Assert(plt.GetPlottables().Count > 0);
     plt.Clear();
     Debug.Assert(plt.GetPlottables().Count == 0);
     Pass();
 }
Esempio n. 2
0
        private void TestEmpty_Click(object sender, EventArgs e)
        {
            formsPlot1.plt.Clear();

            plt.Clear();
            RunBenchmark("Baseline");
        }
Esempio n. 3
0
        public static void Stack(ScottPlot.Plot plt, ABFsharp.ABF abf, double yOffset, bool derivative)
        {
            plt.Clear();

            if (derivative)
            {
                for (int i = 0; i < abf.info.sweepCount; i++)
                {
                    var sweep = abf.GetSweep(i);
                    plt.PlotSignal(Diff(sweep.valuesCopy), abf.info.sampleRate, color: System.Drawing.Color.Red, yOffset: i * yOffset);
                }
                plt.YLabel("Membrane Potential (mV)");
            }
            else
            {
                for (int i = 0; i < abf.info.sweepCount; i++)
                {
                    var sweep = abf.GetSweep(i);
                    plt.PlotSignal(sweep.valuesCopy, abf.info.sampleRate, color: System.Drawing.Color.Blue, yOffset: i * yOffset);
                }
            }

            plt.Title($"Stacked Sweeps");
            plt.XLabel("Sweep Time (seconds)");
            plt.AxisAuto(0, .1);
        }
Esempio n. 4
0
 public static void ContinuouslyModifyPlottables(object data)
 {
     ScottPlot.Plot plt = (ScottPlot.Plot)data;
     while (ContinueModifyingPlottables)
     {
         plt.RenderLock();
         plt.Clear();
         plt.AddSignal(new double[] { 1, 2, 3 });
         plt.RenderUnlock();
     }
 }
Esempio n. 5
0
        public static void RightClickMenuItemClicked(ToolStripItem item, ContextMenuStrip rightClickMenu, ScottPlot.Plot plt)
        {
            Console.WriteLine("CLICKED:" + item.ToString());
            SaveFileDialog savefile = new SaveFileDialog();
            string         itemName = item.ToString();

            if (itemName.StartsWith("About"))
            {
                itemName = "About";
            }

            switch (itemName)
            {
            case "Save Image":
                rightClickMenu.Hide();
                savefile.FileName = "ScottPlot.png";
                savefile.Filter   = "PNG Files (*.png)|*.png|All files (*.*)|*.*";
                if (savefile.ShowDialog() == DialogResult.OK)
                {
                    plt.SaveFig(savefile.FileName);
                }
                break;

            case "Save Data":
                savefile.Title    = "Save data for the first plot object";
                savefile.FileName = "data.csv";
                savefile.Filter   = "CSV Files (*.csv)|*.csv|All files (*.*)|*.*";
                if (savefile.ShowDialog() == DialogResult.OK)
                {
                    plt.GetPlottables()[0].SaveCSV(savefile.FileName);
                }
                break;

            case "Auto-Axis":
                rightClickMenu.Hide();
                plt.AxisAuto();
                break;

            case "Clear":
                rightClickMenu.Hide();
                plt.Clear();
                break;

            case "Toggle quality while dragging":
                plt.mouseTracker.lowQualityWhileDragging = !plt.mouseTracker.lowQualityWhileDragging;
                break;

            case "ScottPlot":
                rightClickMenu.Hide();
                System.Diagnostics.Process.Start("https://github.com/swharden/ScottPlot");
                break;
            }
        }
Esempio n. 6
0
 public static void ContinuouslyModifyPlottables(object data)
 {
     ScottPlot.Plot plt = (ScottPlot.Plot)data;
     while (ContinueModifyingPlottables)
     {
         plt.RenderLock();
         plt.Clear();
         plt.AddSignal(new double[] { 1, 2, 3 });
         plt.RenderUnlock();
     }
     Debug.WriteLine("Modification thread shutting down...");
     Thread.Sleep(100);
 }
Esempio n. 7
0
     public static void ContinuouslyModifyPlottables(object data)
     {
         ScottPlot.Plot plt = (ScottPlot.Plot)data;
         while (ContinueModifyingPlottables)
         {
             // wait for the current render to complete before modifying the plot
             while (plt.IsRendering) /* wait */ } {
             // then be quick to modify it when you do
             plt.Clear();
             plt.PlotSignal(new double[] { 1, 2, 3 });
     }
     Debug.WriteLine("Modification thread shutting down...");
     Thread.Sleep(100);
 }
Esempio n. 8
0
        public string Figure_09_Clearing_Plots()
        {
            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.Clear();
            plt.PlotScatter(dataRandom3, dataRandom4);
            plt.SaveFig(fileName);
            Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}");
            return(name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap()));
        }
Esempio n. 9
0
        public static void Full(ScottPlot.Plot plt, ABFsharp.ABF abf, bool derivative)
        {
            plt.Clear();

            if (!derivative)
            {
                plt.PlotSignal(abf.GetFullRecording(), abf.info.sampleRate * 60, color: System.Drawing.Color.Blue);
                plt.YLabel("Membrane Potential (mV)");
                plt.XLabel("Experiment Time (Minutes)");
            }
            else
            {
                plt.PlotSignal(Diff(abf.GetFullRecording()), abf.info.sampleRate * 60, color: System.Drawing.Color.Red);
                plt.YLabel("Voltage Derivative (mV/ms)");
                plt.XLabel("Experiment Time (Minutes)");
            }

            plt.Title($"Full Recording");
            plt.AxisAuto(0, .1);
        }
Esempio n. 10
0
        /// <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();
        }
Esempio n. 11
0
        public static void Sweep(ScottPlot.Plot plt, ABFsharp.ABF abf, int sweepNumber, bool derivative)
        {
            plt.Clear();

            if (!derivative)
            {
                var sweep = abf.GetSweep((int)sweepNumber);
                plt.PlotSignal(sweep.values, abf.info.sampleRate, color: System.Drawing.Color.Blue);
                plt.YLabel("Membrane Potential (mV)");
            }
            else
            {
                var sweep = abf.GetSweep((int)sweepNumber);
                plt.PlotSignal(Diff(sweep.values), abf.info.sampleRate, color: System.Drawing.Color.Red);
                plt.YLabel("Voltage Derivative (mV/ms)");
            }

            plt.Title($"Sweep {sweepNumber + 1} of {abf.info.sweepCount}");
            plt.XLabel("Sweep Time (seconds)");
            plt.AxisAuto(0, .1);
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        /// <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();
        }