Exemple #1
0
        public void Test_Window_Functions()
        {
            var plt = new ScottPlot.Plot(500, 400);

            double[] xs = ScottPlot.DataGen.Range(-1, 1, .01, true);
            plt.PlotScatter(xs, FftSharp.Window.Hanning(xs.Length), label: "Hanning");
            plt.PlotScatter(xs, FftSharp.Window.Hamming(xs.Length), label: "Hamming");
            plt.PlotScatter(xs, FftSharp.Window.Bartlett(xs.Length), label: "Bartlett");
            plt.PlotScatter(xs, FftSharp.Window.Blackman(xs.Length), label: "Blackman");
            //plt.PlotScatter(xs, FftSharp.Window.BlackmanExact(xs.Length), label: "BlackmanExact");
            //plt.PlotScatter(xs, FftSharp.Window.BlackmanHarris(xs.Length), label: "BlackmanHarris");
            plt.PlotScatter(xs, FftSharp.Window.FlatTop(xs.Length), label: "FlatTop");
            plt.PlotScatter(xs, FftSharp.Window.Cosine(xs.Length), label: "Cosine");

            // customize line styles post-hoc
            foreach (var p in plt.GetPlottables())
            {
                if (p is ScottPlot.PlottableScatter)
                {
                    ((ScottPlot.PlottableScatter)p).markerSize = 0;
                    ((ScottPlot.PlottableScatter)p).lineWidth  = 3;
                    var c = ((ScottPlot.PlottableScatter)p).color;
                    ((ScottPlot.PlottableScatter)p).color = System.Drawing.Color.FromArgb(200, c.R, c.G, c.B);
                }
            }

            plt.Legend(location: ScottPlot.legendLocation.upperRight);
            plt.SaveFig("../../../../../dev/windows.png");
        }
Exemple #2
0
        private void PbPlot_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Middle)
            {
                plt.AxisAuto();
                Render(skipIfCurrentlyRendering: false);
            }
            else if (e.Button == MouseButtons.Right && plt.mouseTracker.mouseDownStopwatch.ElapsedMilliseconds < 100)
            {
                rightClickMenu = new ContextMenuStrip();
                rightClickMenu.Items.Add("Save Image");

                rightClickMenu.Items.Add("Save Data");
                ToolStripMenuItem saveDataMenuItem = (ToolStripMenuItem)rightClickMenu.Items[rightClickMenu.Items.Count - 1];
                saveDataMenuItem.Enabled = false;
                if (plt.GetPlottables().Count > 0)
                {
                    if ((plt.GetPlottables()[0] is PlottableScatter) || (plt.GetPlottables()[0] is PlottableSignal))
                    {
                        saveDataMenuItem.Enabled = true;
                    }
                }

                rightClickMenu.Items.Add("Auto-Axis");
                rightClickMenu.Items.Add("Clear");
                rightClickMenu.Items.Add(new ToolStripSeparator());
                rightClickMenu.Items.Add("Toggle quality while dragging");
                rightClickMenu.Items.Add(new ToolStripSeparator());
                rightClickMenu.Items.Add("Help");

                ToolStripMenuItem helpMenu = (ToolStripMenuItem)rightClickMenu.Items[rightClickMenu.Items.Count - 1];
                helpMenu.DropDownItems.Add("left-click-drag to pan");
                helpMenu.DropDownItems.Add("right-click-drag to zoom");
                helpMenu.DropDownItems.Add("middle-click for auto-axis");
                helpMenu.DropDownItems.Add("double-click to toggle benchmark");
                helpMenu.DropDownItems.Add(new ToolStripSeparator());
                helpMenu.DropDownItems.Add($"ScottPlot {Tools.GetVersionString()} ({Tools.GetFrameworkVersionString()})");
                helpMenu.DropDownItems[0].Enabled = false;
                helpMenu.DropDownItems[1].Enabled = false;
                helpMenu.DropDownItems[2].Enabled = false;
                helpMenu.DropDownItems[3].Enabled = false;

                rightClickMenu.Show(pbPlot, PointToClient(Cursor.Position));
                rightClickMenu.ItemClicked   += new ToolStripItemClickedEventHandler(RightClickMenuItemClicked);
                helpMenu.DropDownItemClicked += new ToolStripItemClickedEventHandler(RightClickMenuItemClicked);
            }
        }
Exemple #3
0
        public void Test_Remove_RemovesSinglePlot()
        {
            var plt = new ScottPlot.Plot();

            Random rand = new Random(0);
            var    barX = plt.PlotPoint(111, 222, label: "X");
            var    sigA = plt.PlotSignal(DataGen.RandomWalk(rand, 100), label: "A");
            var    sigB = plt.PlotSignal(DataGen.RandomWalk(rand, 100), label: "B");
            var    sigC = plt.PlotSignal(DataGen.RandomWalk(rand, 100), label: "C");
            var    sigD = plt.PlotSignal(DataGen.RandomWalk(rand, 100), label: "D");
            var    sigE = plt.PlotSignal(DataGen.RandomWalk(rand, 100), label: "E");
            var    barY = plt.PlotPoint(111, 222, label: "Y");

            Assert.AreEqual("X,A,B,C,D,E,Y", string.Join(",", plt.GetPlottables().Select(x => x.GetLegendItems()[0].label)));
            plt.Remove(sigC);
            Assert.AreEqual("X,A,B,D,E,Y", string.Join(",", plt.GetPlottables().Select(x => x.GetLegendItems()[0].label)));
        }
Exemple #4
0
        private string GetLegendLabels(ScottPlot.Plot plt)
        {
            List <string> names = new List <string>();

            foreach (var plottable in plt.GetPlottables())
            {
                var legendItems = plottable.GetLegendItems();
                if (legendItems != null && legendItems.Length > 0)
                {
                    names.Add(legendItems[0].label);
                }
            }

            return(string.Join(",", names));
        }
Exemple #5
0
        /// <summary>
        /// Return a new Plot with all the same Plottables (and some of the styles) of this one.
        /// This is called when you right-click a plot in a control and hit "open in new window".
        /// </summary>
        public Plot Copy()
        {
            Settings oldSettings = settings;
            Plot     oldPlot     = this;

            Plot newPlot = new Plot(oldSettings.Width, oldSettings.Height);

            foreach (IPlottable oldPlottable in oldPlot.GetPlottables())
            {
                newPlot.Add(oldPlottable);
            }
            newPlot.AxisAuto();

            newPlot.XLabel(oldSettings.XAxis.Label());
            newPlot.YLabel(oldSettings.YAxis.Label());
            newPlot.Title(oldSettings.XAxis2.Label());

            return(newPlot);
        }