public PointPlotSample() : base() { infoText = ""; infoText += "Sinc Function Example. Demonstrates - \n"; infoText += " * Charting LinePlot and PointPlot at the same time. \n"; infoText += " * Adding a legend."; plotCanvas.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] = Math.Sin ((((double)i-50.0)/4.0))/(((double)i-50.0)/4.0); b[i] *= mult; } a[i] += b[i]; } Marker m = new Marker (Marker.MarkerType.Cross1, 6, Colors.Blue); PointPlot pp = new PointPlot (m); pp.OrdinateData = a; pp.AbscissaData = new StartStep (-500.0, 10.0); pp.Label = "Random"; plotCanvas.Add (pp); LinePlot lp = new LinePlot (); lp.OrdinateData = b; lp.AbscissaData = new StartStep( -500.0, 10.0 ); lp.LineColor = Colors.Red; lp.LineWidth = 2; plotCanvas.Add (lp); plotCanvas.Title = "Sinc Function"; plotCanvas.YAxis1.Label = "Magnitude"; plotCanvas.XAxis1.Label = "Position"; Legend legend = new Legend(); legend.AttachTo (XAxisPosition.Top, YAxisPosition.Left); legend.VerticalEdgePlacement = Legend.Placement.Inside; legend.HorizontalEdgePlacement = Legend.Placement.Inside; legend.YOffset = 8; plotCanvas.Legend = legend; plotCanvas.LegendZOrder = 1; // default zorder for adding idrawables is 0, so this puts legend on top. PackStart (plotCanvas.Canvas, true); Label la = new Label (infoText); PackStart (la); }
public PlotMarkerSample() : base() { infoText = ""; infoText += "Markers Example. Demonstrates - \n"; infoText += " * PointPlot and the available marker types \n"; infoText += " * Legends, and how to place them."; plotCanvas.Clear(); double[] y = new double[1] {1.0}; foreach (object i in Enum.GetValues (typeof(Marker.MarkerType))) { Marker m = new Marker( (Marker.MarkerType)Enum.Parse(typeof(Marker.MarkerType), i.ToString()), 8 ); m.FillColor = Colors.Red; 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(); plotCanvas.Add (pp); } plotCanvas.Title = "Markers"; plotCanvas.YAxis1.Label = "Index"; plotCanvas.XAxis1.Label = "Marker"; plotCanvas.YAxis1.WorldMin = 0.0; plotCanvas.YAxis1.WorldMax = 2.0; plotCanvas.XAxis1.WorldMin -= 1.0; plotCanvas.XAxis1.WorldMax += 1.0; Legend legend = new Legend(); legend.AttachTo( XAxisPosition.Top, 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; plotCanvas.Legend = legend; PackStart (plotCanvas.Canvas, true); Label la = new Label (infoText); PackStart (la); }
public LabelPointPlotSample() { infoText = ""; infoText += "Cs2Te Photocathode QE evolution Example. Demonstrates - \n"; infoText += " * LabelPointPlot (allows text to be associated with points) \n"; infoText += " * PointPlot droplines \n"; infoText += " * LabelAxis \n"; infoText += " * PhysicalSpacingMin property of LabelAxis \n"; qeExampleTimerEnabled = true; plotCanvas.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.0 + 12.0 * (double)r.Next(10000) / 10000.0; if (PlotQEExampleValues[i] > 18.0) { 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.LineColor = Colors.CornflowerBlue; pp.Marker.Filled = false; plotCanvas.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); plotCanvas.Add (tp1); LabelAxis la = new LabelAxis (plotCanvas.XAxis1); for (int i=0; i<len; ++i) { la.AddLabel (s[i], i); } Font ff = Font.FromName ("Verdana"); la.TickTextFont = ff.WithSize (7); la.PhysicalSpacingMin = 25; plotCanvas.XAxis1 = la; plotCanvas.Title = "Cs2Te Photocathode QE evolution"; plotCanvas.TitleFont = ff.WithSize (15); plotCanvas.XAxis1.WorldMin = -1.0; plotCanvas.XAxis1.WorldMax = len; plotCanvas.XAxis1.LabelFont = ff.WithSize (10); plotCanvas.XAxis1.Label = "Cathode ID"; plotCanvas.YAxis1.Label = "QE [%]"; plotCanvas.YAxis1.LabelFont = ff.WithSize (10); plotCanvas.YAxis1.TickTextFont = ff.WithSize (10); plotCanvas.YAxis1.WorldMin = 0.0; plotCanvas.YAxis1.WorldMax= 25.0; plotCanvas.XAxis1.TickTextAngle = 60.0; // Add timer into Xwt loop for data updates Application.TimeoutInvoke (750, qeExampleTimer_Tick); PackStart (plotCanvas.Canvas, true); Label info = new Label (infoText); PackStart (info); }
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); }