Encapsulates functionality for plotting data as a stepped line.
Inheritance: BaseSequencePlot, IPlot, ISequencePlot
Beispiel #1
0
        public StepPlotSample()
            : base()
        {
            infoText = "";
            infoText += "Sound Wave Example. Demonstrates - \n";
            infoText += " * StepPlot (centered) and HorizontalLine IDrawables \n";
            //infoText += " * AxisDrag Interaction - try left clicking and dragging X or Y axes \n";
            //infoText += " * Vertical & Horizontal GuideLines - without fragmentation problems! \n";
            //infoText += " * Rubberband Selection - click and drag to zoom an area of the plot \n";
            //infoText += " * Key actions : +,- zoom, left/right/up/down pan, Home restores original scale and origin";

            Assembly asm = Assembly.GetExecutingAssembly ();

            Stream file = asm.GetManifestResourceStream ("Samples.Resources.sound.wav");

            System.Int16[] w = new short[5000];
            byte[] a = new byte[10000];

            file.Read (a, 0, 10000);
            for (int i=100; i<5000; ++i) {
                w[i] = BitConverter.ToInt16 (a,i*2);
            }
            file.Close();

            plotCanvas.Clear();

            //plotCanvas.AddInteraction (new AxisDrag ());
            //plotCanvas.AddInteraction (new KeyActions ());
            //plotCanvas.AddInteraction (new NPlot.PlotSelection (Color.Gray));
            //plotCanvas.AddInteraction (new VerticalGuideline (Color.Gray));
            //plotCanvas.AddInteraction (new HorizontalGuideline (Color.Gray));

            plotCanvas.Add (new HorizontalLine (2500.0, Colors.LightBlue));

            StepPlot sp = new StepPlot ();
            sp.DataSource = w;
            sp.Color = Colors.Yellow;
            sp.Center = true;
            plotCanvas.Add( sp );

            plotCanvas.YAxis1.FlipTicksLabel = true;

            plotCanvas.Canvas.BackgroundColor = new Color (0.375, 0.375, 0.375);
            plotCanvas.PlotBackColor = Colors.DarkBlue;
            plotCanvas.XAxis1.LineColor = Colors.White;
            plotCanvas.YAxis1.LineColor = Colors.White;

            PackStart (plotCanvas.Canvas, true);
            Label la = new Label (infoText);
            PackStart (la);
        }
Beispiel #2
0
        public PlotWave()
            : base()
        {
            infoText = "";
            infoText += "Sound Wave Example. Demonstrates - \n";
            infoText += " * StepPlot (centered) and HorizontalLine IDrawables \n";
            infoText += " * AxisDrag Interaction - try left clicking and dragging X or Y axes \n";
            infoText += " * Vertical & Horizontal GuideLines - without fragmentation problems! \n";
            infoText += " * Rubberband Selection - click and drag to zoom an area of the plot \n";
            infoText += " * Key actions : +,- zoom, left/right/up/down pan, Home restores original scale and origin";

            System.IO.Stream file =
                Assembly.GetExecutingAssembly().GetManifestResourceStream("GtkTest.Resources.sound.wav");

            System.Int16[] w = new short[5000];
            byte[] a = new byte[10000];

            file.Read( a, 0, 10000 );
            for (int i=100; i<5000; ++i) {
                w[i] = BitConverter.ToInt16(a,i*2);
            }
            file.Close();

            plotSurface.Clear();

            plotSurface.AddInteraction (new AxisDrag ());
            plotSurface.AddInteraction (new KeyActions ());
            plotSurface.AddInteraction (new NPlot.PlotSelection (Color.Gray));
            plotSurface.AddInteraction (new VerticalGuideline (Color.Gray));
            plotSurface.AddInteraction (new HorizontalGuideline (Color.Gray));

            plotSurface.Add(new HorizontalLine(0.0, Color.LightBlue));

            StepPlot sp = new StepPlot ();
            sp.DataSource = w;
            sp.Color = Color.Yellow;
            sp.Center = true;
            plotSurface.Add( sp );

            plotSurface.YAxis1.FlipTicksLabel = true;

            plotSurface.PlotBackColor = Color.DarkBlue;
            plotSurface.Canvas.ModifyBg (StateType.Normal, new Gdk.Color (100, 100, 100) );
            plotSurface.XAxis1.Color = Color.White;
            plotSurface.YAxis1.Color = Color.White;

            plotSurface.Refresh();
        }
        /// <summary>
        /// Update (replot) the graphs
        /// </summary>
        public void PlotGraphs()
        {
            if (surface == null)
            {
                surface = new NPlot.Windows.PlotSurface2D();
                tabPageGraphs.Controls.Add(surface);
                surface.Dock = DockStyle.Fill;

                surface2 = new NPlot.Windows.PlotSurface2D();
                surface2.Height = 150;
                tabPageGraphs.Controls.Add(surface2);
                surface2.Dock = DockStyle.Bottom;
            }

            surface.Clear();

            //Add a background grid for better chart readability.
            Grid grid = new Grid();
            grid.VerticalGridType = Grid.GridType.Coarse;
            grid.HorizontalGridType = Grid.GridType.Coarse;
            grid.MajorGridPen = new Pen(Color.LightGray, 1.0f);
            surface.Add(grid);

            LinePlot lp1 = new LinePlot();
            lp1.DataSource = controller.Stats.EvaluationItterations.History;
            lp1.Color = Color.Black;
            lp1.Label = "Itterations";
            surface.Add(lp1);

            LinePlot lp2 = new LinePlot();
            lp2.DataSource = controller.Stats.Nodes.History;
            lp2.Pen = new Pen(Color.Green, 2.0f);
            lp2.Label = "Nodes";
            surface.Add(lp2);

            LinePlot lp3 = new LinePlot();
            lp3.DataSource = controller.Stats.Duplicates.History;
            lp3.Pen = new Pen(Color.Orange, 1.0f);
            lp3.Label = "Duplicates";
            surface.Add(lp3);

            LinePlot lp4 = new LinePlot();
            lp4.DataSource = controller.Stats.DeadNodes.History;
            lp4.Pen = new Pen(Color.Red, 1.5f);
            lp4.Label = "Dead";
            surface.Add(lp4);

            LinePlot lp6 = new LinePlot();
            lp6.DataSource = controller.Stats.AvgEvalList.History;
            lp6.Pen = new Pen(Color.Brown, 1.3f);
            lp6.Label = "Eval List";
            surface.Add(lp6);

            LinePlot lp7 = new LinePlot();
            lp7.DataSource = controller.Stats.NodesFwd.History;
            lp7.Pen = new Pen(Color.Brown, 1.0f);
            lp7.Pen.DashStyle = DashStyle.Dash;
            lp7.Label = "Nodes Fwd";
            surface.Add(lp7);

            LinePlot lp8 = new LinePlot();
            lp8.DataSource = controller.Stats.NodesRev.History;
            lp8.Pen = new Pen(Color.Cyan, 1.0f);
            lp8.Pen.DashStyle = DashStyle.Dash;
            lp8.Label = "Nodes Rev";
            surface.Add(lp8);

            surface.XAxis1.Label = "Elapsed Time (sec)";
            surface.YAxis1.Label = "Total";
            surface.Legend = new Legend();

            surface.SmoothingMode = SmoothingMode.HighQuality;
            surface.Title = "Solver | Node Information";

            surface.Refresh();

            surface2.Clear();
            StepPlot lp5 = new StepPlot();
            lp5.Pen = new Pen(Color.Fuchsia, 2f);
            lp5.DataSource = controller.Stats.NodesPerSecond.History;
            lp5.Label = "Nodes/s";
            surface2.Add(lp5);

            surface2.XAxis1.Label = "Elapsed Time (sec)";
            surface2.YAxis1.Label = "Rate (node/sec)";
            surface2.Legend = new Legend();
            surface2.SmoothingMode = SmoothingMode.HighQuality;
            surface2.Refresh();
        }
Beispiel #4
0
        public PlotMockup()
        {
            infoText = "";
            infoText +=   "THE TEST (can your charting library handle this?) - \n";
            infoText +=   "NPlot demonstrates it can handle real world charting requirements.";

            // first of all, generate some mockup data.
            DataTable info = new DataTable( "Store Information" );
            info.Columns.Add( "Index", typeof(int) );
            info.Columns.Add( "IndexOffsetLeft", typeof(float) );
            info.Columns.Add( "IndexOffsetRight", typeof(float) );
            info.Columns.Add( "StoreName", typeof(string) );
            info.Columns.Add( "BarBase", typeof(float) );
            info.Columns.Add( "StoreGrowth", typeof(float) );
            info.Columns.Add( "AverageGrowth", typeof(float) );
            info.Columns.Add( "ProjectedSales", typeof(float) );

            float barBase = 185.0f;
            Random r = new Random();
            for (int i=0; i<18; ++i)
            {
                DataRow row = info.NewRow();
                row["Index"] = i;
                row["IndexOffsetLeft"] = (float)i - 0.1f;
                row["IndexOffsetRight"] = (float)i + 0.1f;
                row["StoreName"] = "Store " + (i+1).ToString();
                row["BarBase"] = barBase;
                row["StoreGrowth"] = barBase + ( (r.NextDouble() - 0.1) * 20.0f );
                row["AverageGrowth"] = barBase + ( (r.NextDouble() - 0.1) * 15.0f );
                row["ProjectedSales"] = barBase + ( r.NextDouble() * 15.0f );
                info.Rows.Add( row );
                barBase += (float)r.NextDouble() * 4.0f;
            }

            plotSurface.Clear();

            plotSurface.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            // generate the grid
            Grid grid = new Grid();
            grid.VerticalGridType = Grid.GridType.Coarse;
            grid.HorizontalGridType = Grid.GridType.None;
            grid.MajorGridPen = new Pen( Color.Black, 1.0f );
            plotSurface.Add( grid );

            // generate the trendline
            LinePlot trendline = new LinePlot();
            trendline.DataSource = info;
            trendline.AbscissaData = "Index";
            trendline.OrdinateData = "BarBase";
            trendline.Pen = new Pen( Color.Black, 3.0f );
            trendline.Label = "Trendline";
            plotSurface.Add( trendline );

            // draw store growth bars
            BarPlot storeGrowth = new BarPlot();
            storeGrowth.DataSource = info;
            storeGrowth.AbscissaData = "IndexOffsetLeft";
            storeGrowth.OrdinateDataTop = "StoreGrowth";
            storeGrowth.OrdinateDataBottom = "BarBase";
            storeGrowth.Label = "Store Growth";
            storeGrowth.FillBrush = NPlot.RectangleBrushes.Solid.Black;
            //storeGrowth.BorderPen = new Pen( Color.Black, 2.0f );
            plotSurface.Add( storeGrowth );

            // draw average growth bars
            BarPlot averageGrowth = new BarPlot();
            averageGrowth.DataSource = info;
            averageGrowth.AbscissaData = "IndexOffsetRight";
            averageGrowth.OrdinateDataBottom = "BarBase";
            averageGrowth.OrdinateDataTop = "AverageGrowth";
            averageGrowth.Label = "Average Growth";
            averageGrowth.FillBrush = NPlot.RectangleBrushes.Solid.Gray;
            //averageGrowth.BorderPen = new Pen( Color.Black, 2.0f );
            plotSurface.Add( averageGrowth );

            // generate the projected sales step line.
            StepPlot projected = new StepPlot();
            projected.DataSource = info;
            projected.AbscissaData = "Index";
            projected.OrdinateData = "ProjectedSales";
            projected.Pen = new Pen( Color.Orange, 3.0f );
            projected.HideVerticalSegments = true;
            projected.Center = true;
            projected.Label = "Projected Sales";
            projected.WidthScale = 0.7f;
            plotSurface.Add( projected );

            // generate the minimum target line.
            HorizontalLine minimumTargetLine = new HorizontalLine( 218, new Pen( Color.Green, 3.5f ) );
            minimumTargetLine.Label = "Minimum Target";
            minimumTargetLine.LengthScale = 0.98f;
            minimumTargetLine.ShowInLegend = true; // off by default for lines.
            plotSurface.Add( minimumTargetLine );

            // generate the preferred target line.
            HorizontalLine preferredTargetLine = new HorizontalLine( 228, new Pen( Color.Blue, 3.5f ) );
            preferredTargetLine.Label = "Preferred Target";
            preferredTargetLine.LengthScale = 0.98f;
            preferredTargetLine.ShowInLegend = true; // off by default for lines.
            plotSurface.Add( preferredTargetLine );

            // make some modifications so that chart matches requirements.
            // y axis.
            plotSurface.YAxis1.TicksIndependentOfPhysicalExtent = true;
            plotSurface.YAxis1.TickTextNextToAxis = false;
            //plotSurface.YAxis1.TicksAngle = 3.0f * (float)Math.PI / 2.0f; // Not required if TicksAngle bug #2000693 fixed
            ((LinearAxis)plotSurface.YAxis1).LargeTickStep = 10.0;
            ((LinearAxis)plotSurface.YAxis1).NumberOfSmallTicks = 0;

            // x axis
            plotSurface.XAxis1.TicksIndependentOfPhysicalExtent = true;
            plotSurface.XAxis1.TickTextNextToAxis = false;
            //plotSurface.XAxis1.TicksAngle = (float)Math.PI / 2.0f; // Not required if TicksAngle bug #2000693 fixed
            LabelAxis la = new LabelAxis( plotSurface.XAxis1 );
            for (int i=0; i<info.Rows.Count; ++i)
            {
                la.AddLabel( (string)info.Rows[i]["StoreName"], Convert.ToInt32(info.Rows[i]["Index"]) );
            }
            la.TicksLabelAngle = (float)90.0f;
            la.TicksBetweenText = true;
            plotSurface.XAxis1 = la;

            plotSurface.XAxis2 = (Axis)plotSurface.XAxis1.Clone();
            plotSurface.XAxis2.HideTickText = true;
            plotSurface.XAxis2.LargeTickSize = 0;

            Legend l = new Legend();
            l.NumberItemsVertically = 2;
            l.AttachTo( XAxisPosition.Bottom, YAxisPosition.Left );
            l.HorizontalEdgePlacement = NPlot.Legend.Placement.Outside;
            l.VerticalEdgePlacement = NPlot.Legend.Placement.Inside;
            l.XOffset = 5;
            l.YOffset = 50;
            l.BorderStyle = NPlot.LegendBase.BorderType.Line;

            plotSurface.Legend = l;

            plotSurface.Title =
                "Sales Growth Compared to\n" +
                "Average Sales Growth by Store Size - Rank Order Low to High";

            plotSurface.Refresh();
        }
Beispiel #5
0
        public PlotParticles()
        {
            infoText = "";
            infoText += "Particles Example. Demonstrates - \n";
            infoText += " * How to chart multiple data sets against multiple axes at the same time.";

            plotSurface.Clear();

            Grid mygrid = new Grid();
            mygrid.HorizontalGridType = Grid.GridType.Fine;
            mygrid.VerticalGridType = Grid.GridType.Fine;
            plotSurface.Add( mygrid );

            // in this example we synthetize a particle distribution
            // in the x-x' phase space and plot it, with the rms Twiss
            // ellipse and desnity distribution
            const int Particle_Number = 500;
            float [] x = new float[Particle_Number];
            float [] y = new float[Particle_Number];
            // Twiss parameters for the beam ellipse
            // 5 mm mrad max emittance, 1 mm beta function
            float alpha, beta, gamma, emit;
            alpha = -2.0f;
            beta = 1.0f;
            gamma = (1.0f + alpha * alpha) / beta;
            emit = 4.0f;

            float da, xmax, xpmax;
            da = -alpha / gamma;
            xmax = (float)Math.Sqrt(emit / gamma);
            xpmax = (float)Math.Sqrt(emit * gamma);

            Random rand = new Random();

            // cheap randomizer on the unit circle
            for (int i = 0; i<Particle_Number; i++)
            {
                float r;
                do
                {
                    x[i] = (float)(2.0f * rand.NextDouble() - 1.0f);
                    y[i] = (float)(2.0f * rand.NextDouble() - 1.0f);
                    r = (float)Math.Sqrt(x[i] * x[i] + y[i] * y[i]);
                } while (r > 1.0f);
            }

            // transform to the tilted twiss ellipse
            for (int i =0; i<Particle_Number; ++i)
            {
                y[i] *= xpmax;
                x[i] = x[i] * xmax + y[i] * da;
            }
            plotSurface.Title = "Beam Horizontal Phase Space and Twiss ellipse";

            PointPlot pp = new PointPlot();
            pp.OrdinateData = y;
            pp.AbscissaData = x;
            pp.Marker = new Marker(Marker.MarkerType.FilledCircle ,4, new Pen(Color.Blue));
            plotSurface.Add(pp, XAxisPosition.Bottom, YAxisPosition.Left);

            // set axes
            LinearAxis lx = (LinearAxis) plotSurface.XAxis1;
            lx.Label = "Position - x [mm]";
            lx.NumberOfSmallTicks = 2;
            LinearAxis ly = (LinearAxis) plotSurface.YAxis1;
            ly.Label = "Divergence - x' [mrad]";
            ly.NumberOfSmallTicks = 2;

            // Draws the rms Twiss ellipse computed from the random data
            float [] xeli=new float [40];
            float [] yeli=new float [40];

            float a_rms, b_rms, g_rms, e_rms;

            Twiss(x, y, out a_rms, out b_rms, out g_rms, out e_rms);
            TwissEllipse(a_rms, b_rms, g_rms, e_rms, ref xeli, ref yeli);

            LinePlot lp = new LinePlot();
            lp.OrdinateData = yeli;
            lp.AbscissaData = xeli;
            plotSurface.Add(lp, XAxisPosition.Bottom, YAxisPosition.Left);
            lp.Pen = new Pen( Color.Red, 2.0f );
            // Draws the ellipse containing 100% of the particles
            // for a uniform distribution in 2D the area is 4 times the rms
            float [] xeli2 = new float [40];
            float [] yeli2 = new float [40];
            TwissEllipse(a_rms, b_rms, g_rms, 4.0F * e_rms, ref xeli2, ref yeli2);

            LinePlot lp2 = new LinePlot();
            lp2.OrdinateData = yeli2;
            lp2.AbscissaData = xeli2;
            plotSurface.Add( lp2, XAxisPosition.Bottom, YAxisPosition.Left );
            Pen p2 = new Pen( Color.Red, 2.0f );
            float [] pattern = { 5.0f, 40.0f };
            p2.DashPattern = pattern;
            lp2.Pen = p2;

            // now bin the particle position to create beam density histogram
            float range, min, max;
            min = (float)lx.WorldMin;
            max = (float)lx.WorldMax;
            range = max - min;

            const int Nbin = 30;
            float [] xbin = new float[Nbin+1];
            float [] xh = new float[Nbin+1];

            for (int j=0; j<=Nbin; ++j){
                xbin[j] = min + j * range;
                if (j < Nbin) xh[j] = 0.0F;
            }
            for (int i =0; i<Particle_Number; ++i) {
                if (x[i] >= min && x[i] <= max) {
                    int j;
                    j = Convert.ToInt32(Nbin * (x[i] - min) / range);
                    xh[j] += 1;
                }
            }
            StepPlot sp= new StepPlot();
            sp.OrdinateData = xh;
            sp.AbscissaData = new StartStep( min, range / Nbin );
            sp.Center = true;
            plotSurface.Add(sp, XAxisPosition.Bottom, YAxisPosition.Right);
            // axis formatting
            LinearAxis ly2 = (LinearAxis)plotSurface.YAxis2;
            ly2.WorldMin = 0.0f;
            ly2.Label = "Beam Density [a.u.]";
            ly2.NumberOfSmallTicks = 2;
            sp.Pen = new Pen( Color.Green, 2 );

            // Finally, refreshes the plot
            plotSurface.Refresh();
        }
Beispiel #6
0
        private void InitializePlots()
        {
            object plot = new object();

               for (int j = 1; j < 7; j++)
               {
                    switch (j)
                    {
                         case 1:
                              plot = plotSurface2D1;
                              break;
                         case 2:
                              plot = plotSurface2D2;
                              break;
                         case 3:
                              plot = plotSurface2D3;
                              break;
                         case 4:
                              plot = plotSurface2D4;
                              break;
                         case 5:
                              plot = plotSurface2D5;
                              break;
                         case 6:
                              plot = plotSurface2D6;
                              break;
                    }

                    NPlot.Windows.PlotSurface2D plotter = (NPlot.Windows.PlotSurface2D)plot;

                    plotter.Clear();
                    plotter.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;

                    NPlot.Grid grid = new NPlot.Grid();
                    grid.VerticalGridType = NPlot.Grid.GridType.Coarse;
                    grid.HorizontalGridType = NPlot.Grid.GridType.Coarse;
                    grid.MinorGridPen = new Pen(Color.Blue, 1.0f);
                    grid.MajorGridPen = new Pen(Color.LightGray, 1.0f);

                    plotter.Add(grid);

                    StepPlot stepBalance = new StepPlot();
                    stepBalance.Pen = new Pen(Color.Green, 2);

                    List<Int32> balanceAxis = new List<Int32>();

                    List<decimal> balanceAmount = new List<decimal>();

                    for (int i = 0; i < 10; i++)
                         balanceAxis.Add(0);

                    stepBalance.AbscissaData = balanceAxis;
                    stepBalance.DataSource = balanceAmount;
                    plotter.Add(stepBalance);
                    plotter.ShowCoordinates = true;
                    plotter.AutoScaleAutoGeneratedAxes = true;
                    plotter.RightMenu = NPlot.Windows.PlotSurface2D.DefaultContextMenu;
                    plotter.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(false));
                    plotter.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag());
                    plotter.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag());

                    //Refresh surfaces.
                    plotter.Refresh();
               }
        }
Beispiel #7
0
        public void PlotWave()
        {
            string[] lines = {
                "Sound Wave Example. Demonstrates - ",
                "  * StepPlot (centered) and HorizontalLine IDrawables",
                "  * How to set colors of various things.",
                "  * A few plot interactions. Try left clicking and dragging (a) the axes (b) in the plot region.",
                "  * In the future I plan add a plot interaction for axis drag that knows if the ctr key is down. This will select between drag/scale" };
            infoBox.Lines = lines;

            //FileStream fs = new FileStream( @"c:\light.wav", System.IO.FileMode.Open );
            System.IO.Stream file =
                Assembly.GetExecutingAssembly().GetManifestResourceStream("NPlotDemo.resources.light.wav");

            System.Int16[] w = new short[5000];
            byte[] a = new byte[10000];
            file.Read( a, 0, 10000 );
            for (int i=100; i<5000; ++i)
            {
                w[i] = BitConverter.ToInt16(a,i*2);
            }

            file.Close();

            plotSurface.Clear();
            plotSurface.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalGuideline());
            plotSurface.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalRangeSelection(3));
            plotSurface.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(true));

            plotSurface.Add(new HorizontalLine(0.0, Color.LightBlue));

            StepPlot sp = new StepPlot();
            sp.DataSource = w;
            sp.Color = Color.Yellow;
            sp.Center = true;
            plotSurface.Add( sp );

            plotSurface.YAxis1.FlipTicksLabel = true;

            plotSurface.PlotBackColor = Color.DarkBlue;
            plotSurface.BackColor = Color.Black;
            plotSurface.XAxis1.Color = Color.White;
            plotSurface.YAxis1.Color = Color.White;

            plotSurface.Refresh();
        }