Пример #1
0
        public void CreatePlot(InteractivePlotSurface2D plotSurface)
        {
            plotSurface.Clear();

            double[] y = new double[1] { 1.0f };
            foreach (object i in Enum.GetValues(typeof(Marker.MarkerType)))
            {
                Marker m = new Marker((Marker.MarkerType)Enum.Parse(typeof(Marker.MarkerType), i.ToString()), 8);
                double[] x = new double[1];
                x[0] = (double)m.Type;
                PointPlot pp = new PointPlot();
                pp.OrdinateData = y;
                pp.AbscissaData = x;
                pp.Marker = m;
                pp.Label = m.Type.ToString();
                plotSurface.Add(pp);
            }
            plotSurface.Title = "Markers";
            plotSurface.YAxis1.Label = "Index";
            plotSurface.XAxis1.Label = "Marker";
            plotSurface.YAxis1.WorldMin = 0.0f;
            plotSurface.YAxis1.WorldMax = 2.0f;
            plotSurface.XAxis1.WorldMin -= 1.0f;
            plotSurface.XAxis1.WorldMax += 1.0f;

            Legend legend = new Legend();
            legend.AttachTo(PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Right);
            legend.VerticalEdgePlacement = Legend.Placement.Outside;
            legend.HorizontalEdgePlacement = Legend.Placement.Inside;
            legend.XOffset = 5; // note that these numbers can be negative.
            legend.YOffset = 0;
            plotSurface.Legend = legend;

            plotSurface.Refresh();
        }
Пример #2
0
        public void CreatePlot()
        {
            costPS.Clear();
            //costPS.DateTimeToolTip = true;

            // obtain stock information from xml file
            DataSet ds = new DataSet();
            System.IO.Stream file =
                Assembly.GetExecutingAssembly().GetManifestResourceStream("DemoLib.Resources.asx_jbh.xml");
            ds.ReadXml(file, System.Data.XmlReadMode.ReadSchema);
            DataTable dt = ds.Tables[0];
            DataView dv = new DataView(dt);

            // create CandlePlot.
            CandlePlot cp = new CandlePlot();
            cp.DataSource = dt;
            cp.AbscissaData = "Date";
            cp.OpenData = "Open";
            cp.LowData = "Low";
            cp.HighData = "High";
            cp.CloseData = "Close";
            cp.BearishColor = Color.Red;
            cp.BullishColor = Color.Green;
            cp.Style = CandlePlot.Styles.Filled;
            costPS.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            costPS.Add(new Grid());
            costPS.Add(cp);
            costPS.Title = "AU:JBH";
            costPS.YAxis1.Label = "Price [$]";
            costPS.YAxis1.LabelOffset = 40;
            costPS.YAxis1.LabelOffsetAbsolute = true;
            costPS.XAxis1.HideTickText = true;
            costPS.SurfacePadding = 5;
            costPS.AddInteraction(new PlotDrag(true, true));
            costPS.AddInteraction(new AxisDrag());
            costPS.InteractionOccurred += costPS_InteractionOccured;
            costPS.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60));

            PointPlot pp = new PointPlot();
            pp.Marker = new Marker(Marker.MarkerType.Square, 0);
            pp.Marker.Pen = new Pen(Color.Red, 5.0f);
            pp.Marker.DropLine = true;
            pp.DataSource = dt;
            pp.AbscissaData = "Date";
            pp.OrdinateData = "Volume";
            volumePS.Add(pp);
            volumePS.YAxis1.Label = "Volume";
            volumePS.YAxis1.LabelOffsetAbsolute = true;
            volumePS.YAxis1.LabelOffset = 40;
            volumePS.SurfacePadding = 5;
            volumePS.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60));
            volumePS.AddInteraction(new AxisDrag());
            volumePS.AddInteraction(new PlotDrag(true, false));
            volumePS.InteractionOccurred += volumePS_InteractionOccured;
            volumePS.PreRefresh += volumePS_PreRefresh;

            //this.costPS.RightMenu = new ReducedContextMenu();
        }
Пример #3
0
        public void CreatePlot(InteractivePlotSurface2D plotSurface)
        {
            plotSurface.Clear(); // clear everything. reset fonts. remove plot components etc.

            System.Random r = new Random();
            double[] a = new double[100];
            double[] b = new double[100];
            double mult = 0.00001f;
            for (int i = 0; i < 100; ++i)
            {
                a[i] = ((double)r.Next(1000) / 5000.0f - 0.1f) * mult;
                if (i == 50) { b[i] = 1.0f * mult; }
                else
                {
                    b[i] = (double)Math.Sin((((double)i - 50.0f) / 4.0f)) / (((double)i - 50.0f) / 4.0f);
                    b[i] *= mult;
                }
                a[i] += b[i];
            }

            Marker m = new Marker(Marker.MarkerType.Cross1, 6, new Pen(Color.Blue, 2.0F));
            PointPlot pp = new PointPlot(m);
            pp.OrdinateData = a;
            pp.AbscissaData = new StartStep(-500.0, 10.0);
            pp.Label = "Random";
            plotSurface.Add(pp);

            LinePlot lp = new LinePlot();
            lp.OrdinateData = b;
            lp.AbscissaData = new StartStep(-500.0, 10.0);
            lp.Pen = new Pen(Color.Red, 2.0f);
            plotSurface.Add(lp);

            plotSurface.Title = "Sinc Function";
            plotSurface.YAxis1.Label = "Magnitude";
            plotSurface.XAxis1.Label = "Position";

            Legend legend = new Legend();
            legend.AttachTo(PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Left);
            legend.VerticalEdgePlacement = Legend.Placement.Inside;
            legend.HorizontalEdgePlacement = Legend.Placement.Inside;
            legend.YOffset = 8;

            plotSurface.Legend = legend;
            plotSurface.LegendZOrder = 1; // default zorder for adding idrawables is 0, so this puts legend on top.

            plotSurface.Refresh();
        }
Пример #4
0
        public static void Run(InteractiveHost plot)
        {
            // All the toolkit specific code does is one of these lines:
            // InteractiveHost plot = new Florence.GtkSharp.InteractiveHost();
            // InteractiveHost plot = new Florence.WinForms.InteractiveHost();

            // Start the interactive host; this starts up a GUI thread
            // and otherwise gets the GUI ready to go.
            plot.Start();

            // Generate some data to plot!
            var rand = new Random(0);

            var x = new double[100];
            for (int ii = 0; ii < x.Length; ++ii)
                x[ii] = rand.NextNormal(0.0, 1.0);

            var y = new double[x.Length];
            for (int ii = 0; ii < y.Length; ++ii)
                y[ii] = 2.0 + 3.0 * x[ii] + rand.NextNormal(0.0, 2.5);

            var t = new DateTime[15];
            var s = new double[t.Length];
            t[0] = new DateTime(2013,12,1);
            s[0] = 100.0;

            for (int ii = 1; ii < t.Length; ++ii)
            {
                t[ii] = t[ii-1].AddDays(1);
                s[ii] = s[ii - 1]*Math.Exp(rand.NextNormal(0.05 / 365.0, 0.15 / Math.Sqrt(365.0)));
            }

            // Create our first plot
            var plot1 = new PointPlot() { AbscissaData = x, OrdinateData = y };
            plot.Add(plot1);
            plot.XAxis1.Label = "Love of Graphs";
            plot.YAxis1.Label = "Overall Awesomeness";
            plot.Title = "Effect of Graph Affinity on Overall Awesomeness";

            // Pause execution. In an interactive environment, (C#/F# REPL) this would not be necessary
            Console.ReadLine();

            // Try putting your mouse over the numbers on either the X or Y axis,
            // pressing the mouse button then dragging left and right (for the X)
            // or up and down (for the Y).

            // Now try clicking and dragging in the main plot area.

            // Now press enter, to move on to the next example

            plot.newFigure();
            plot.Title = "A new one!";

            Console.ReadLine();

            plot.previous();
            plot.Title = "First one again!";

            Console.ReadLine();

            plot.next();
            plot.closeFigure();

            var line_plot = plot.newFigure();

            line_plot.Add(new LinePlot() { AbscissaData = t, OrdinateData = s });

            //var plot2 = new LinePlot() { AbscissaData = x, OrdinateData = y };
            //plot.Title = "Test Plot 2";
            //plot.XAxis1.Label = "X2";
            //plot.YAxis1.Label = "Y2";
            //plot.Add(plot2);

            Console.ReadLine();

            plot.Stop();
        }
Пример #5
0
        /// <summary>
        /// Might need Refresh () afterwards!
        /// </summary>
        /// <param name="table2D">
        /// A <see cref="Table2D"/>
        /// </param>
        public void Draw(Tables.Denso.Table2D table2D)
        {
            float[] valuesY = table2D.GetValuesYasFloats ();

            // clear everything. reset fonts. remove plot components etc.
            // including Florence interactions
            this.plotSurface2D.Clear ();

            // Florence interactions, N/A in original NPlot library
            // guideline disadvantage: not optimized - does not use bitmap buffer, refreshes every time a line has to move
            plotSurface2D.AddInteraction (new VerticalGuideline (Color.Gray));
            plotSurface2D.AddInteraction (new HorizontalGuideline (Color.Gray));

            //plotSurface2D.AddInteraction (new PlotSelection (Color.Green));
            plotSurface2D.AddInteraction (new PlotDrag (true, true));

            plotSurface2D.AddInteraction (new AxisDrag ());
            // PlotZoom: mouse wheel zoom
            plotSurface2D.AddInteraction (new PlotZoom ());
            plotSurface2D.AddInteraction (new KeyActions ());

            plotSurface2D.SurfacePadding = 0;
            plotSurface2D.SmoothingMode = SmoothingMode;

            // y-values, x-values (!)
            LinePlot lp = new LinePlot (valuesY, table2D.ValuesX);
            lp.Pen = pen;

            PointPlot pp = new PointPlot (marker);
            pp.AbscissaData = table2D.ValuesX;
            pp.OrdinateData = valuesY;

            Grid myGrid = new Grid ();
            myGrid.VerticalGridType = Grid.GridType.Coarse;
            myGrid.HorizontalGridType = Grid.GridType.Coarse;

            plotSurface2D.Add (myGrid);
            plotSurface2D.Add (pp);
            plotSurface2D.Add (lp);

            plotSurface2D.TitleFont = titleFont;
            plotSurface2D.Title = table2D.Title;

            plotSurface2D.XAxis1.LabelFont = labelFont;
            plotSurface2D.XAxis1.Label = AxisText (table2D.NameX, table2D.UnitX);
            // could use ex: plotSurface2D.YAxis1.NumberFormat = "0.000";
            plotSurface2D.XAxis1.TickTextFont = tickTextFont;

            plotSurface2D.YAxis1.LabelFont = labelFont;
            plotSurface2D.YAxis1.Label = AxisText (table2D.Title, table2D.UnitY);
            plotSurface2D.YAxis1.TickTextFont = tickTextFont;

            // Florence surface has Refresh () method vs. NPlot: Refresh () not part of surface interface
            plotSurface2D.Refresh ();
        }
Пример #6
0
        public void CreatePlot(InteractivePlotSurface2D plotSurface)
        {
            this.plotSurface = plotSurface;

            this.Timer = new System.Timers.Timer();
            this.Timer.Interval = 500;
            this.Timer.Elapsed += new ElapsedEventHandler(Timer_Elapsed);
            this.Timer.Enabled = true;
            plotSurface.Clear();

            int len = 24;
            string[] s = new string[len];
            PlotQEExampleValues = new double[len];
            PlotQEExampleTextValues = new string[len];

            Random r = new Random();

            for (int i = 0; i < len; i++)
            {
                PlotQEExampleValues[i] = 8.0f + 12.0f * (double)r.Next(10000) / 10000.0f;
                if (PlotQEExampleValues[i] > 18.0f)
                {
                    PlotQEExampleTextValues[i] = "KCsTe";
                }
                else
                {
                    PlotQEExampleTextValues[i] = "";
                }
                s[i] = i.ToString("00") + ".1";
            }

            PointPlot pp = new PointPlot();
            pp.DataSource = PlotQEExampleValues;
            pp.Marker = new Marker(Marker.MarkerType.Square, 10);
            pp.Marker.DropLine = true;
            pp.Marker.Pen = Pens.CornflowerBlue;
            pp.Marker.Filled = false;
            plotSurface.Add(pp);

            LabelPointPlot tp1 = new LabelPointPlot();
            tp1.DataSource = PlotQEExampleValues;
            tp1.TextData = PlotQEExampleTextValues;
            tp1.LabelTextPosition = LabelPointPlot.LabelPositions.Above;
            tp1.Marker = new Marker(Marker.MarkerType.None, 10);
            plotSurface.Add(tp1);

            LabelAxis la = new LabelAxis(plotSurface.XAxis1);
            for (int i = 0; i < len; ++i)
            {
                la.AddLabel(s[i], i);
            }
            FontFamily ff = new FontFamily("Verdana");
            la.TickTextFont = new Font(ff, 7);
            la.PhysicalSpacingMin = 25;
            plotSurface.XAxis1 = la;

            plotSurface.Title = "Cs2Te Photocathode QE evolution";
            plotSurface.TitleFont = new Font(ff, 15);
            plotSurface.XAxis1.WorldMin = -1.0f;
            plotSurface.XAxis1.WorldMax = len;
            plotSurface.XAxis1.LabelFont = new Font(ff, 10);
            plotSurface.XAxis1.Label = "Cathode ID";
            plotSurface.YAxis1.Label = "QE [%]";
            plotSurface.YAxis1.LabelFont = new Font(ff, 10);
            plotSurface.YAxis1.TickTextFont = new Font(ff, 10);

            plotSurface.YAxis1.WorldMin = 0.0;
            plotSurface.YAxis1.WorldMax = 25.0;

            plotSurface.XAxis1.TicksLabelAngle = 60.0f;

            plotSurface.Refresh();
        }
Пример #7
0
        public void CreatePlot(InteractivePlotSurface2D plotSurface)
        {
            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, PlotSurface2D.XAxisPosition.Bottom, PlotSurface2D.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, PlotSurface2D.XAxisPosition.Bottom, PlotSurface2D.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, PlotSurface2D.XAxisPosition.Bottom, PlotSurface2D.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 dx = range / Nbin;
            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, PlotSurface2D.XAxisPosition.Bottom, PlotSurface2D.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();
        }