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 PointPlotContainer(DataChart source, PlotLine line) : base(source) { Plot = new NPlot.PointPlot(); Plot.DataSource = line.Data; Plot.AbscissaData = source.XAxis; Plot.OrdinateData = line.Expression; Plot.Marker.Type = Marker.MarkerType.Circle; this.Expression = line.Expression; plotInterface = Plot; PlotYAxis = new Axis(); source.Plot.Add(Plot, XAxisPosition.Bottom, YAxisPosition.Left, 0, null, PlotYAxis); }
public void DisplayNumberOfWinnersGraph(DataSet dt) { var 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 = "Percent"; pp.OrdinateData = "Winners"; _grapWinningPercentages.Text = "Number of Contenders"; _grapWinningPercentages.Add(pp); _grapWinningPercentages.YAxis1.Label = "Number Of Winners"; _grapWinningPercentages.YAxis1.LabelOffsetAbsolute = true; _grapWinningPercentages.YAxis1.LabelOffset = 40; _grapWinningPercentages.Padding = 5; _grapWinningPercentages.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60)); }
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); }
/// <summary> /// Might need Refresh () afterwards! /// </summary> /// <param name="table2D"> /// A <see cref="Table2D"/> /// </param> public void Draw(Table2D table2D) { float[] valuesY = table2D.GetValuesYasFloats (); // clear everything. reset fonts. remove plot components etc. this.plotSurface2D.Clear (); plotSurface2D.Padding = 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 (lp); plotSurface2D.Add (pp); 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; // Refresh () not part of interface! }
public PlotQE() { 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"; infoText += "You cannot interact with this chart"; qeExampleTimerEnabled = 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(); // Add timer into Gtk loop for data updates GLib.Timeout.Add( 500, new GLib.TimeoutHandler(qeExampleTimer_Tick) ); }
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(); }
public FinancialDemo() : base("Multiple linked plot demo") { // // Gtk Window Setup // InitializeComponent(); costPS.Clear(); // obtain stock information from xml file DataSet ds = new DataSet(); System.IO.Stream file = Assembly.GetExecutingAssembly().GetManifestResourceStream("GtkTest.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 NPlot.PlotDrag(true,true)); costPS.AddInteraction(new NPlot.AxisDrag()); costPS.InteractionOccurred += new NPlot.InteractivePlotSurface2D.InteractionHandler(costPS_InteractionOccurred); costPS.AddAxesConstraint(new AxesConstraint.Position(YAxisPosition.Left, 60)); costPS.Refresh(); 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.Position(YAxisPosition.Left, 60)); volumePS.AddInteraction(new NPlot.AxisDrag()); volumePS.AddInteraction(new NPlot.PlotDrag(true,false)); volumePS.InteractionOccurred += new NPlot.InteractivePlotSurface2D.InteractionHandler(volumePS_InteractionOccurred); volumePS.PreRefresh += new NPlot.InteractivePlotSurface2D.PreRefreshHandler(volumePS_PreRefresh); volumePS.Refresh(); }
private void RefreshRetrievePlot() { _retrieveSpeedPlot.Clear(); PointPlot plot = new PointPlot(); List<DateTime> timePoints; List<double> retrieveMbPerSecond; ComputePlotAverage(out timePoints, out retrieveMbPerSecond); plot.AbscissaData = timePoints; plot.DataSource = retrieveMbPerSecond; Grid grid = new Grid(); grid.HorizontalGridType = Grid.GridType.Coarse; grid.VerticalGridType = Grid.GridType.Coarse; _retrieveSpeedPlot.Add(grid); _retrieveSpeedPlot.Add(plot); _retrieveSpeedPlot.ShowCoordinates = true; _retrieveSpeedPlot.YAxis1.Label = "Mb/sec"; _retrieveSpeedPlot.YAxis1.LabelOffsetAbsolute = true; _retrieveSpeedPlot.YAxis1.LabelOffset = 40; _retrieveSpeedPlot.Padding = 5; //Align percent plot axes. DateTimeAxis ax = new DateTimeAxis(_retrieveSpeedPlot.XAxis1); ax.HideTickText = false; _retrieveSpeedPlot.XAxis1 = ax; _retrieveSpeedPlot.Refresh(); }
private void SetPlots(int p, List<double[]> fitPoints) { object plot = new object(); object curve = new object(); IBasisFunction basis = new RBFBasis.ThinPlateSpline(null); switch (Basis) { case BasisType.Cubic: basis = new RBFBasis.PolyHarmonic3(null); break; case BasisType.Gaussian: basis = new RBFBasis.Gaussian(null); break; case BasisType.Line: basis = new RBFBasis.CustomBasis(null, 0, 0, 1, 0); break; case BasisType.Parabolic: basis = new RBFBasis.ThinPlateSpline2(null); break; case BasisType.CubicParabolic: if (p % 2 == 0) basis = new RBFBasis.PolyHarmonic3(null); else basis = new RBFBasis.CustomBasis(null, 1, 1, -1, 0); break; } switch (p) { case 1: plot = plotSurface2D1; //basis = new RBFBasis.Exponential(null); p1Curve = new RBFCurve(null, "RBF " + p, fitPoints, basis, new RBFPolynomials.Linear(null), 0.0); curve = p1Curve; break; case 2: plot = plotSurface2D2; //basis = new RBFBasis.Exponential(null); p2Curve = new RBFCurve(null, "RBF " + p, fitPoints, basis, new RBFPolynomials.Linear(null), 0.0); curve = p2Curve; break; case 3: plot = plotSurface2D3; //basis = new RBFBasis.Exponential(null); p3Curve = new RBFCurve(null, "RBF " + p, fitPoints, basis, new RBFPolynomials.Linear(null), 0.0); curve = p3Curve; break; case 4: plot = plotSurface2D4; //basis = new RBFBasis.Exponential(null); p4Curve = new RBFCurve(null, "RBF " + p, fitPoints, basis, new RBFPolynomials.Linear(null), 0.0); curve = p4Curve; break; case 5: plot = plotSurface2D5; //basis = new RBFBasis.Exponential(null); p5Curve = new RBFCurve(null, "RBF " + p, fitPoints, basis, new RBFPolynomials.Linear(null), 0.0); curve = p5Curve; break; case 6: plot = plotSurface2D6; // basis = new RBFBasis.Exponential(null); p6Curve = new RBFCurve(null, "RBF " + p, fitPoints, basis, new RBFPolynomials.Linear(null), 0.0); curve = p6Curve; break; } if (Max[0] < fitPoints.Max(pt => pt[0])) Max[0] = fitPoints.Max(pt => pt[0]); if (Max[1] < fitPoints.Max(pt => pt[1])) Max[1] = fitPoints.Max(pt => pt[1]); if (Min[0] > fitPoints.Min(pt => pt[0])) Min[0] = fitPoints.Min(pt => pt[0]); if (Min[1] > fitPoints.Min(pt => pt[1])) Min[1] = fitPoints.Min(pt => pt[1]); NPlot.Windows.PlotSurface2D plotter = (NPlot.Windows.PlotSurface2D)plot; RBFCurve RBF = (RBFCurve)curve; //RBF = new RBFCurve(null, "RBF " + p, fitPoints, basis, new RBFPolynomials.Linear(null), 0.0); plotter.Clear(); plotter.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; //Add a background grid for better chart readability. 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); int length = fitPoints.Count * 5; //Create a step plot instance for the balance chart. LinePlot speed = new LinePlot(); PointPlot pplot = new PointPlot(); speed.Pen = new Pen(Color.Blue, 1); //Create the lists from which to pull data. List<Int32> countaxis = new List<Int32>(); List<Int32> Pplotcountaxis = new List<Int32>(); List<decimal> speedlist = new List<decimal>(); for (int i = 0; i < length; i++) countaxis.Add(i); for (int i = 0; i < fitPoints.Count; i++) Pplotcountaxis.Add((int)fitPoints[i][0]); //Populate the balanceAmount list double[] pnt; List<decimal> pointsList = fitPoints.ConvertAll(new Converter<double[], decimal>((double[] dd) => { return Convert.ToDecimal(dd[1]); })); for (int i = 0; i < length; i++) { pnt = new double[] { (double)i, 0 }; RBF.Value(ref pnt); speedlist.Add(Convert.ToDecimal(pnt[1])); } //foreach (double value in pent.Speeds) //{ // speedlist.Add(Convert.ToDecimal(value) / 1200); //} pplot.AbscissaData = Pplotcountaxis; pplot.DataSource = pointsList; speed.AbscissaData = countaxis; speed.DataSource = speedlist; //Add stepBalance to plotSurfaceBalance. plotter.Add(speed); plotter.Add(pplot); //Balance plot general settings. plotter.ShowCoordinates = true; //plotter.YAxis1.WorldMax = 10; //plotter.YAxis1.WorldMin = 0; //this.YAxis1. plotter.AutoScaleAutoGeneratedAxes = true; plotter.AddAxesConstraint(new AxesConstraint.AxisPosition(NPlot.PlotSurface2D.YAxisPosition.Left, 60)); //Label Label1 = new Label(); //Label1.Font = new Font(Label1.Font, FontStyle.Bold); //plotter.YAxis1. plotter.YAxis1.Label = "Y"; plotter.YAxis1.LabelFont = new Font(this.Font, FontStyle.Bold); plotter.YAxis1.LabelOffsetAbsolute = true; plotter.XAxis1.Label = "X"; plotter.XAxis1.LabelFont = new Font(this.Font, FontStyle.Bold); plotter.YAxis1.LabelOffset = 40; plotter.XAxis1.HideTickText = false; plotter.Padding = 5; 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()); plotter.Title = basis.Label; plotter.TitleFont = new Font(this.Font, FontStyle.Bold); //} //Refresh surfaces. plotter.Refresh(); }
public void PlotMarkers() { string[] lines = { "Markers Example. Demonstrates - ", " * PointPlot and the available marker types", " * Legends, and how to place them." }; infoBox.Lines = lines; 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(); }
private void PlotSincFunction() { string[] lines = { "Sinc Function Example. Demonstrates - ", " * Charting line and point plot at the same time.", " * Adding a legend." }; infoBox.Lines = lines; 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(); }
public void PlotQE() { 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 ); 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(); }
public void PlotMarkers() { 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; plotSurface.Legend = legend; plotSurface.Refresh(); }
private void PlotSincFunction() { 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; plotSurface.Legend = new Legend(); plotSurface.Refresh(); }
void p1BRW_ProgressChanged(object sender, ProgressChangedEventArgs e) { if (p1BRW.CancellationPending == true) Algo.Stop(); m_progBar.Value = e.ProgressPercentage; if (e.UserState == null) return; List<int> bestChromo = (List<int>)e.UserState; if (bestChromo.Count > 0) { List<double[]> GAPnts = new List<double[]>(); double[] result = EvalChromosome(ref bestChromo, ref GAPnts); object curve = new object(); object plot = new object(); for (int j = 0; j < 1; j++) { switch (j + 1) { case 1: curve = p1Curve; plot = plotSurface2D1; break; case 2: curve = p2Curve; plot = plotSurface2D2; break; case 3: curve = p3Curve; plot = plotSurface2D3; break; case 4: curve = p4Curve; plot = plotSurface2D4; break; case 5: curve = p5Curve; plot = plotSurface2D5; break; case 6: curve = p6Curve; plot = plotSurface2D6; break; } RBFCurve oldRBF = curve as RBFCurve; CustomBasis GeneticBasis = new CustomBasis(16.383 / 2.0 - result[0], 16.383 / 2.0 - result[1], 16.383 / 2.0 - result[2], 16.383 / 2.0 - result[3]); //List<double[]> fitpoints = new List<double[]>(oldRBF.OriginalFitPoints); List<double[]> fitpoints = new List<double[]>(GAPnts); if (RemoveExtraFitPoints) { fitpoints.RemoveAt(1); fitpoints.RemoveAt(2); } RBFCurve GaRBF = new RBFCurve(null, "GA RBF", fitpoints, GeneticBasis, new Linear(null), 0.0); NPlot.Windows.PlotSurface2D plotter = (NPlot.Windows.PlotSurface2D)plot; plotter.Clear(); plotter.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; //Add a background grid for better chart readability. 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); int length = oldRBF.FitPoints.Count * 5; //Create a step plot instance for the balance chart. LinePlot speed = new LinePlot(); LinePlot speed2 = new LinePlot(); PointPlot pplot = new PointPlot(); PointPlot pplot2 = new PointPlot(); pplot2.Marker = new Marker(Marker.MarkerType.Cross1, 10, System.Drawing.Color.Red); speed.Pen = new Pen(Color.Blue, 1); //Create the lists from which to pull data. List<Int32> countaxis = new List<Int32>(); List<Int32> Pplotcountaxis = new List<Int32>(); List<Int32> Pplotcountaxis2 = new List<Int32>(); List<decimal> speedlist = new List<decimal>(); List<decimal> speedlist2 = new List<decimal>(); for (int i = 0; i < length; i++) countaxis.Add(i); for (int i = 0; i < oldRBF.FitPoints.Count; i++) Pplotcountaxis.Add((int)oldRBF.OriginalFitPoints[i][0]); for (int i = 0; i < GaRBF.FitPoints.Count; i++) Pplotcountaxis2.Add((int)GaRBF.OriginalFitPoints[i][0]); //Populate the balanceAmount list double[] pnt; List<decimal> pointsList = oldRBF.OriginalFitPoints.ConvertAll(new Converter<double[], decimal>((double[] dd) => { return Convert.ToDecimal(dd[1]); })); List<decimal> pointsList2 = GaRBF.OriginalFitPoints.ConvertAll(new Converter<double[], decimal>((double[] dd) => { return Convert.ToDecimal(dd[1]); })); for (int i = 0; i < length; i++) { pnt = new double[] { (double)i, 0 }; oldRBF.Value(ref pnt); speedlist.Add(Convert.ToDecimal(pnt[1])); pnt = new double[] { (double)i, 0 }; GaRBF.Value(ref pnt); speedlist2.Add(Convert.ToDecimal(pnt[1])); } pplot.AbscissaData = Pplotcountaxis; pplot.DataSource = pointsList; pplot2.AbscissaData = Pplotcountaxis2; pplot2.DataSource = pointsList2; speed.AbscissaData = countaxis; speed.DataSource = speedlist; speed2.AbscissaData = countaxis; speed2.DataSource = speedlist2; //Add stepBalance to plotSurfaceBalance. plotter.Add(speed); plotter.Add(speed2); plotter.Add(pplot); plotter.Add(pplot2); //Balance plot general settings. plotter.ShowCoordinates = true; plotter.AutoScaleAutoGeneratedAxes = true; plotter.AddAxesConstraint(new AxesConstraint.AxisPosition(NPlot.PlotSurface2D.YAxisPosition.Left, 60)); plotter.YAxis1.Label = "Y"; plotter.YAxis1.LabelFont = new Font(this.Font, FontStyle.Bold); plotter.YAxis1.LabelOffsetAbsolute = true; plotter.XAxis1.Label = "X"; plotter.XAxis1.LabelFont = new Font(this.Font, FontStyle.Bold); plotter.YAxis1.LabelOffset = 40; plotter.XAxis1.HideTickText = false; plotter.Padding = 5; 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()); plotter.Title = GeneticBasis.ToString(); plotter.TitleFont = new Font(this.Font, FontStyle.Bold); //} //Refresh surfaces. plotter.Refresh(); } Application.DoEvents(); } }
public void UpdatePlot() { m_nsPlot.Clear(); m_nsPlot.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; m_nsPlot.BackColor = Color.FromKnownColor(KnownColor.Control); NPlot.Grid grid = new NPlot.Grid(); grid.VerticalGridType = NPlot.Grid.GridType.Coarse; grid.HorizontalGridType = NPlot.Grid.GridType.Coarse; grid.MinorGridPen = new Pen(Color.LightSlateGray, 1.0f); grid.MajorGridPen = new Pen(Color.SlateGray, 1.0f); Color LINE = Color.RoyalBlue; Color VERT = Color.LightSkyBlue; Color MARK = Color.SteelBlue; m_nsPlot.Add(grid); LinePlot combLine = new LinePlot(); combLine.Pen = new Pen(LINE, 2); List<decimal> combX = new List<decimal>(); List<decimal> combY = new List<decimal>(); RBF.RBFSpline rbf = FitRBF(); double[] p = new double[1]; double s = 0; int CNT = 50; for (int i = 0; i < CNT; i++) { s = BLAS.interpolant(i, CNT); rbf.BsVal(s, ref p); combX.Add(Convert.ToDecimal(s)); combY.Add(Convert.ToDecimal(p[0])); } combLine.AbscissaData = combX; combLine.DataSource = combY; m_nsPlot.Add(combLine); combX = new List<decimal>(); combY = new List<decimal>(); List<double> vertsX; List<double> vertsY; foreach (Vect2 v in CombPnts) { //add comb point for marker combX.Add(Convert.ToDecimal(v[0])); combY.Add(Convert.ToDecimal(v[1])); //create vertical comb line vertsX = new List<double>(2); vertsY = new List<double>(2); vertsX.Add(v[0]); vertsX.Add(v[0]); vertsY.Add(v[1]); vertsY.Add(0); LinePlot ver = new LinePlot(vertsY, vertsX); ver.Pen = new Pen(VERT, 2f); m_nsPlot.Add(ver); } PointPlot combPoints = new PointPlot(new Marker(Marker.MarkerType.Circle, 12)); combPoints.AbscissaData = combX; combPoints.DataSource = combY; combPoints.Marker.Pen = new Pen(MARK, 1f); m_nsPlot.Add(combPoints); //combPoints = new PointPlot(new Marker(Marker.MarkerType.Cross1, 7)); //combPoints.AbscissaData = combX; //combPoints.DataSource = combY; //combPoints.Marker.Pen = new Pen(MARK, 1f); //m_nsPlot.Add(combPoints); m_nsPlot.ShowCoordinates = true; //curvePlot.AutoScaleAutoGeneratedAxes = true; m_nsPlot.RightMenu = NPlot.Windows.PlotSurface2D.DefaultContextMenu; //m_plot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(false)); //m_plot.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60)); //m_plot.YAxis1.Label = ""; //m_plot.YAxis1.LabelFont = new Font(this.Font, FontStyle.Bold); //m_plot.YAxis1.LabelOffsetAbsolute = true; //m_plot.XAxis1.Label = ""; //m_plot.XAxis1.LabelFont = new Font(this.Font, FontStyle.Bold); //m_plot.YAxis1.LabelOffset = 30; m_nsPlot.XAxis1.HideTickText = false; m_nsPlot.Refresh(); //m_plot.Padding = 5; // m_plot.TitleFont = new Font(this.Font, FontStyle.Bold); }
private void UpdateEkarGraph(DataSet ekarDs, DataSet averageEkar) { const float penWidth = 2.0F; _ekarGraphCtrl.Clear(); var pp = new PointPlot(); pp.Marker = new Marker(Marker.MarkerType.Cross1, 6, new Pen(Color.Red, penWidth)); pp.Marker.Pen = new Pen(Color.Red, penWidth); pp.Marker.DropLine = true; pp.DataSource = ekarDs; pp.AbscissaData = "Count"; pp.OrdinateData = "Ekar"; var mygrid = new Grid(); mygrid.HorizontalGridType = Grid.GridType.Fine; mygrid.VerticalGridType = Grid.GridType.Fine; _ekarGraphCtrl.Add(mygrid); _ekarGraphCtrl.Add(pp); _ekarGraphCtrl.Padding = 1; _ekarGraphCtrl.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60)); _ekarGraphCtrl.XAxis1.IncreaseRange(0.10); var pp1 = new PointPlot(); pp1.Marker = new Marker(Marker.MarkerType.FilledSquare, 1, new Pen(Color.Blue, 2.0F)); pp1.Marker.DropLine = false; pp1.AbscissaData = "Count"; pp1.OrdinateData = "AvEkar"; pp1.DataSource = averageEkar; _ekarGraphCtrl.Add(pp1); _ekarGraphCtrl.Refresh(); }