Exemple #1
0
        public StackedHistogram()
        {
            infoText = "";
            infoText += "Stacked Histogram Sample. Also demonstrates - \n";
            infoText += " * Label Axis with angled text. \n";
            infoText += " * ColorGradient Bars fill";

            plotCanvas.Clear();

            Grid myGrid = new Grid();
            myGrid.VerticalGridType = Grid.GridType.Coarse;
            double[] pattern = {1.0, 2.0};
            myGrid.MajorGridDash = pattern;

            myGrid.MajorGridColor = Colors.LightGray;
            plotCanvas.Add (myGrid);

            // set up Histogram dataSets manually
            double[] xs = {20.0, 31.0, 27.0, 38.0, 24.0, 3.0, 2.0};
            double[] xs2 = {7.0, 10.0, 42.0, 9.0, 2.0, 79.0, 70.0};
            double[] xs3 = {1.0, 20.0, 20.0, 25.0, 10.0, 30.0, 30.0};

            HistogramPlot hp1 = new HistogramPlot ();
            hp1.DataSource = xs;
            hp1.BaseWidth = 0.6;
            hp1.FillGradient = new ColorGradient (Colors.LightGreen, Colors.White);
            hp1.Filled = true;
            hp1.Label = "Developer Work";

            HistogramPlot hp2 = new HistogramPlot ();
            hp2.DataSource = xs2;
            hp2.Label = "Web Browsing";
            hp2.FillGradient = new ColorGradient (Colors.LightBlue, Colors.White);
            hp2.Filled = true;
            hp2.StackedTo (hp1);

            HistogramPlot hp3 = new HistogramPlot ();
            hp3.DataSource = xs3;
            hp3.Label = "P2P Downloads";
            hp3.FillGradient = new ColorGradient (Colors.Red, Colors.White);
            hp3.Filled = true;
            hp3.StackedTo (hp2);

            plotCanvas.Add (hp1);
            plotCanvas.Add (hp2);
            plotCanvas.Add (hp3);

            plotCanvas.Legend = new Legend();

            LabelAxis la = new LabelAxis (plotCanvas.XAxis1);
            la.AddLabel ("Monday", 0.0);
            la.AddLabel ("Tuesday", 1.0);
            la.AddLabel ("Wednesday", 2.0);
            la.AddLabel ("Thursday", 3.0);
            la.AddLabel ("Friday", 4.0);
            la.AddLabel ("Saturday", 5.0);
            la.AddLabel ("Sunday", 6.0);
            la.Label = "Days";
            la.TickTextFont = Font.FromName ("Courier New").WithSize (8);
            la.TicksBetweenText = true;

            plotCanvas.XAxis1 = la;
            plotCanvas.YAxis1.WorldMin = 0.0;
            plotCanvas.YAxis1.Label = "MBytes";
            ((LinearAxis)plotCanvas.YAxis1).NumberOfSmallTicks = 1;

            plotCanvas.Title = "Internet useage for user:\n johnc 09/01/03 - 09/07/03";

            plotCanvas.XAxis1.TickTextAngle = 30.0;

            PackStart (plotCanvas.Canvas, true);
            Label l = new Label (infoText);
            PackStart (l);
        }
Exemple #2
0
        public PlotParticles()
        {
            infoText = "";
            infoText += "Particles Example. Demonstrates - \n";
            infoText += " * How to chart multiple data sets against multiple axes at the same time.";

            plotCanvas.Clear();

            Grid mygrid = new Grid ();
            mygrid.HorizontalGridType = Grid.GridType.Fine;
            mygrid.VerticalGridType = Grid.GridType.Fine;
            plotCanvas.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;
            double [] x = new double [Particle_Number];
            double [] y = new double [Particle_Number];
            // Twiss parameters for the beam ellipse
            // 5 mm mrad max emittance, 1 mm beta function
            double alpha, beta, gamma, emit;
            alpha = -2.0;
            beta = 1.0;
            gamma = (1.0 + alpha * alpha) / beta;
            emit = 4.0;

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

            Random rand = new Random ();

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

            // 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;
            }
            plotCanvas.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, Colors.Blue);
            plotCanvas.Add (pp, XAxisPosition.Bottom, YAxisPosition.Left);

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

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

            double 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;
            plotCanvas.Add (lp, XAxisPosition.Bottom, YAxisPosition.Left);
            lp.LineColor = Colors.Red;
            lp.LineWidth = 2;
            // Draws the ellipse containing 100% of the particles
            // for a uniform distribution in 2D the area is 4 times the rms
            double [] xeli2 = new double [40];
            double [] yeli2 = new double [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;
            plotCanvas.Add (lp2, XAxisPosition.Bottom, YAxisPosition.Left);
            double[] pattern = new double[] { 5, 20 };
            lp2.LineDash = pattern;
            lp2.LineColor = Colors.Red;

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

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

            for (int j=0; j<=Nbin; ++j){
                xbin[j] = min + j * range;
                if (j < Nbin) xh[j] = 0.0;
            }
            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;
            plotCanvas.Add (sp, XAxisPosition.Bottom, YAxisPosition.Right);
            // axis formatting
            LinearAxis ly2 = (LinearAxis)plotCanvas.YAxis2;
            ly2.WorldMin = 0.0f;
            ly2.Label = "Beam Density [a.u.]";
            ly2.NumberOfSmallTicks = 2;
            sp.Color = Colors.Green;

            PackStart (plotCanvas.Canvas, true);
            Label la = new Label (infoText);
            PackStart (la);
        }