private void ScatterButton_Click(object sender, EventArgs e) { // generate some random Y data int pointCount = 20; double[] ys = RandomWalk(pointCount); // create a line plot containing the data var linePlot = new NPlot.PointPlot { DataSource = ys }; // add the line plot to the plot surface (user control) plotSurface2D1.Clear(); plotSurface2D1.Add(linePlot); plotSurface2D1.Title = $"Point Plot ({pointCount:n0} points)"; plotSurface2D1.YAxis1.Label = "Vertical Axis Label"; plotSurface2D1.XAxis1.Label = "Horizontal Axis Label"; plotSurface2D1.Refresh(); // allow the plot to be mouse-interactive plotSurface2D1.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag()); plotSurface2D1.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag()); plotSurface2D1.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(true)); }
public void AddPointPlot( IEnumerable <TX> xSeries, XAxisPosition xpos, IEnumerable <TY> ySeries, YAxisPosition ypos, MarkerType _markerType, int MarkerSize, Color MarkerColor, bool MarkerFilled, bool ShowLabelInLegend) { NPlot.PointPlot plot = new NPlot.PointPlot(); plot.AbscissaData = xSeries; plot.OrdinateData = ySeries; plot.Marker = new NPlot.Marker(ToNPlotMarkerType(_markerType), MarkerSize, MarkerColor); plot.ShowInLegend = ShowLabelInLegend; MyPlot my = new MyPlot(); my.plot = plot; my.XAxisPosition = xpos == XAxisPosition.Bottom ? NPlot.PlotSurface2D.XAxisPosition.Bottom : NPlot.PlotSurface2D.XAxisPosition.Top; my.YAxisPosition = ypos == YAxisPosition.Left ? NPlot.PlotSurface2D.YAxisPosition.Left : NPlot.PlotSurface2D.YAxisPosition.Right; plots.Add(my); }
private void SaveFromConsoleApplication() { // simulate plotting from a console application var linePlot = new NPlot.PointPlot { DataSource = RandomWalk(20) }; var surface = new NPlot.Bitmap.PlotSurface2D(400, 300); surface.BackColor = Color.White; surface.Add(linePlot); surface.Title = $"Scatter Plot from a Console Application"; surface.YAxis1.Label = "Vertical Axis Label"; surface.XAxis1.Label = "Horizontal Axis Label"; surface.Refresh(); surface.Bitmap.Save("nplot-console-quickstart.png"); }
private void RePlot() { nplot.Clear(); // ensure user has selected both x and y if (Node == null || LabelX == null || LabelY == null) return; //find the associated col index int colx = -1, coly = -1, i = 0; foreach (DataGridViewColumn col in Data.Grid.Columns) { if (col.HeaderText == LabelX) colx = i; if (col.HeaderText == LabelY) coly = i; i++; } if (colx == -1 || coly == -1) return; // get the data from the gridview List<double> x = new List<double>(Data.Grid.Rows.Count); List<double> y = new List<double>(Data.Grid.Rows.Count); double tx, ty; foreach (DataGridViewRow row in Data.Grid.Rows) { try { if (row.Cells[colx].Value == null || row.Cells[coly].Value == null) continue; tx = Double.Parse(row.Cells[colx].Value.ToString()); ty = Double.Parse(row.Cells[coly].Value.ToString()); x.Add(tx); y.Add(ty); } catch (Exception e) { MessageBox.Show(e.Message); } } nplot.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); nplot.Add(grid); //create a lineplot from it NPlot.LinePlot lp = new NPlot.LinePlot(); lp.AbscissaData = x; lp.OrdinateData = y; nplot.Add(lp); //point plot for showing points NPlot.PointPlot pp = new NPlot.PointPlot(); pp.AbscissaData = x; pp.OrdinateData = y; nplot.Add(pp); //format axes labels nplot.YAxis1.Label = LabelY; nplot.YAxis1.LabelFont = new Font(this.Font, FontStyle.Regular); nplot.YAxis1.LabelOffsetAbsolute = true; nplot.YAxis1.LabelOffset = 40; nplot.XAxis1.Label = LabelX; nplot.XAxis1.LabelFont = new Font(this.Font, FontStyle.Regular); nplot.XAxis1.HideTickText = false; nplot.Padding = 5; //enable dragging etc nplot.RightMenu = NPlot.Windows.PlotSurface2D.DefaultContextMenu; nplot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(false)); nplot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag()); nplot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag()); nplot.Refresh(); }