public void LoadPriceBars(Bookmark <IPriceBar> priceBars) { int maxIndex = priceBars.Count; double[] opens = new double[maxIndex]; double[] highs = new double[maxIndex]; double[] lows = new double[maxIndex]; double[] closes = new double[maxIndex]; double[] times = new double[maxIndex]; for (int i = 0; i < maxIndex; i++) { IPriceBar priceBar = priceBars[i]; opens[i] = priceBar.Open; highs[i] = priceBar.High; lows[i] = priceBar.Low; closes[i] = priceBar.Close; times[i] = i; } CandlePlot cp = new CandlePlot(); cp.OpenData = opens; cp.HighData = highs; cp.LowData = lows; cp.CloseData = closes; cp.AbscissaData = times; plotSurface.Clear(); plotSurface.Add(cp); plotSurface.Refresh(); }
private void SetAxes(NPlot.Bitmap.PlotSurface2D npSurface, Font AxisFont, Font TickFont) { //X axis npSurface.XAxis1.Label = "Time"; npSurface.XAxis1.NumberFormat = "{0:####0.0}"; npSurface.XAxis1.TicksLabelAngle = 90; npSurface.XAxis1.TickTextNextToAxis = true; npSurface.XAxis1.FlipTicksLabel = true; npSurface.XAxis1.LabelOffset = 110; npSurface.XAxis1.LabelOffsetAbsolute = true; npSurface.XAxis1.LabelFont = AxisFont; npSurface.XAxis1.TickTextFont = TickFont; //Y axis npSurface.YAxis1.Label = this.Title; npSurface.YAxis1.NumberFormat = "{0:####0.0}"; npSurface.YAxis1.LabelFont = AxisFont; npSurface.YAxis1.TickTextFont = TickFont; //Legend definition: NPlot.Legend npLegend = new NPlot.Legend(); npLegend.AttachTo(NPlot.PlotSurface2D.XAxisPosition.Top, NPlot.PlotSurface2D.YAxisPosition.Right); npLegend.VerticalEdgePlacement = Legend.Placement.Inside; npLegend.HorizontalEdgePlacement = Legend.Placement.Outside; npLegend.BorderStyle = NPlot.LegendBase.BorderType.Line; npLegend.XOffset = -5; npLegend.YOffset = -20; npLegend.BackgroundColor = Color.White; npSurface.Legend = npLegend; //Update PlotSurface: npSurface.Refresh(); }
public void ShowSpectrum(string Filename) { try { while (!_spectrumProcess.HasExited) { Thread.Sleep(50); } } catch (Exception ex) { logger.Error(ex, "Failed to get spectrum results"); return; } LinePlot lp = new LinePlot(); PointPlot pp = new PointPlot(); NPlot.Bitmap.PlotSurface2D npSurface = new NPlot.Bitmap.PlotSurface2D(1000, 1000); try { Tuple <float[], float[]> Data = ReadFile(Filename); if (Data == null) { return; } lp.AbscissaData = Data.Item1; lp.DataSource = Data.Item2; lp.Color = System.Drawing.Color.Green; npSurface.Add(lp); npSurface.XAxis1.Label = "Frequncy [Hz]"; npSurface.YAxis1.Label = "Power [db]"; npSurface.Title = "Central Frequncy = " + (_central_frequncy / 1e6).ToString() + " MHz - Bandwidth = " + (_rate / 1e6).ToString() + " MHz"; npSurface.BackColor = System.Drawing.Color.White; npSurface.Refresh(); MemoryStream ms = new MemoryStream(); npSurface.Bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); ms.Position = 0; Gtk.Application.Invoke(delegate { Pixbuf p = new Gdk.Pixbuf(ms); image.Pixbuf = p; }); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
protected override Image DoCreateChartImage() { var surface = new PlotSurface2D(Parameters.ChartWidth, Parameters.ChartHeight); var plot = new LinePlot { OrdinateData = Parameters.SeriaData.Select(t => t.Key).ToArray(), AbscissaData = Parameters.SeriaData.Select(t => t.Value).ToArray() }; surface.Add(plot); surface.Refresh(); return surface.Bitmap; }
public PriceAction() { plotSurface = new NPlot.Bitmap.PlotSurface2D(700, 500); string infoText = ""; infoText += "Simple CandlePlot example. Demonstrates - \n"; infoText += " * Setting candle plot datapoints using arrays \n"; infoText += " * Plot Zoom interaction using MouseWheel "; plotSurface.Clear(); FilledRegion fr = new FilledRegion( new VerticalLine(1.2), new VerticalLine(2.4)); fr.Brush = Brushes.BlanchedAlmond; plotSurface.Add(fr); // note that arrays can be of any type you like. int[] opens = { 1, 2, 1, 2, 1, 3 }; double[] closes = { 2, 2, 2, 1, 2, 1 }; float[] lows = { 0, 1, 1, 1, 0, 0 }; System.Int64[] highs = { 3, 2, 3, 3, 3, 4 }; int[] times = { 0, 1, 2, 3, 4, 5 }; CandlePlot cp = new CandlePlot(); cp.CloseData = closes; cp.OpenData = opens; cp.LowData = lows; cp.HighData = highs; cp.AbscissaData = times; plotSurface.Add(cp); HorizontalLine line = new HorizontalLine(1.2); line.LengthScale = 0.89f; plotSurface.Add(line, -10); VerticalLine line2 = new VerticalLine(1.2); line2.LengthScale = 0.89f; plotSurface.Add(line2); plotSurface.AddInteraction(new PlotZoom()); plotSurface.Title = "Line in the Title Number 1\nFollowed by another title line\n and another"; plotSurface.Refresh(); }
/// <summary> /// Create a 2-dimensional surface plot of the specified statistic data. /// </summary> /// <param name="ordinateData">The Y-axis data values.</param> /// <param name="abscissaData">The X-axis data values.</param> /// <returns>The plot image bitmap.</returns> private static Bitmap Plot(IList ordinateData, IList abscissaData) { PlotSurface2D plotSurface2D = new PlotSurface2D(200, 200); plotSurface2D.SmoothingMode = SmoothingMode.HighQuality; LinePlot linePlot = new LinePlot(ordinateData, abscissaData); linePlot.ShadowColor = Color.Beige; linePlot.Pen = new Pen(Color.Blue); linePlot.Pen.Width = 1.0f; plotSurface2D.Add(linePlot); plotSurface2D.Refresh(); return plotSurface2D.Bitmap; }
/// <summary> /// Create a 2-dimensional surface plot of the specified statistic data. /// </summary> /// <param name="ordinateData">The Y-axis data values.</param> /// <param name="abscissaData">The X-axis data values.</param> /// <returns>The plot image bitmap.</returns> private static Bitmap Plot(IList ordinateData, IList abscissaData) { PlotSurface2D plotSurface2D = new PlotSurface2D(200, 200); plotSurface2D.SmoothingMode = SmoothingMode.HighQuality; LinePlot linePlot = new LinePlot(ordinateData, abscissaData); linePlot.ShadowColor = Color.Beige; linePlot.Pen = new Pen(Color.Blue); linePlot.Pen.Width = 1.0f; plotSurface2D.Add(linePlot); plotSurface2D.Refresh(); return(plotSurface2D.Bitmap); }
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"); }
public void RefreshSpeed() { List <double> xVal = new List <double>(); List <double> yVal = new List <double>(); for (int x = 0; x < 100000; x++) { xVal.Add(x); yVal.Add(1 - x); } Stopwatch sw = new Stopwatch(); Stopwatch sw2 = new Stopwatch(); LinePlot p1 = new LinePlot(yVal, xVal); PlotSurface2D plot = new PlotSurface2D(640, 480); sw.Start(); plot.Add(p1); plot.Add(p1); plot.Add(p1); plot.Add(p1); plot.Add(p1); plot.Add(p1); plot.Add(p1); plot.Add(p1); plot.Add(p1); plot.Add(p1); sw2.Start(); plot.Refresh(); sw2.Stop(); sw.Stop(); Console.WriteLine(sw2.Elapsed.TotalSeconds.ToString() + " seconds to refresh"); Console.WriteLine(sw.Elapsed.TotalSeconds.ToString() + " seconds To add and refresh"); }
public void RefreshSpeed() { List<double> xVal = new List<double>(); List<double> yVal = new List<double>(); for (int x = 0; x < 100000; x++) { xVal.Add(x); yVal.Add(1 - x); } Stopwatch sw = new Stopwatch(); Stopwatch sw2 = new Stopwatch(); LinePlot p1 = new LinePlot(yVal, xVal); PlotSurface2D plot = new PlotSurface2D(640, 480); sw.Start(); plot.Add(p1); plot.Add(p1); plot.Add(p1); plot.Add(p1); plot.Add(p1); plot.Add(p1); plot.Add(p1); plot.Add(p1); plot.Add(p1); plot.Add(p1); sw2.Start(); plot.Refresh(); sw2.Stop(); sw.Stop(); Console.WriteLine(sw2.Elapsed.TotalSeconds.ToString() + " seconds to refresh"); Console.WriteLine(sw.Elapsed.TotalSeconds.ToString() + " seconds To add and refresh"); }
static void Main(string[] args) { //string file = File.ReadAllText(@"C:\Users\abradu\Desktop\Personal\Flights\284F4A90C57F3FA3E04E364FE6ACB925.json"); string file = File.ReadAllText(@"C:\Users\abradu\Desktop\Personal\Flights\20056AD50DEFACE5A912E9076752BA70.json"); Blackbox bb = new JavaScriptSerializer().Deserialize <Blackbox>(file); bb.ConvertToNatives(); bb.SVT(); for (int i = 0; i < bb.altitude.Count; i++) { bb.altitude[i] = bb.altitude[i] / 1000; } NPlot.Bitmap.PlotSurface2D npSurface = new NPlot.Bitmap.PlotSurface2D(10000, 1000); NPlot.LinePlot npPlot1 = new LinePlot(); NPlot.LinePlot npPlot2 = new LinePlot(); NPlot.LinePlot npPlot3 = new LinePlot(); NPlot.LinePlot npPlot4 = new LinePlot(); NPlot.LinePlot npPlot5 = new LinePlot(); npSurface.Clear(); npSurface.Title = "Line Graph"; npSurface.BackColor = System.Drawing.Color.White; //Left Y axis grid: NPlot.Grid p = new Grid(); NPlot.HistogramPlot h = new HistogramPlot(); npSurface.Add(p, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left); //Phi: npPlot1.AbscissaData = bb.time; npPlot1.DataSource = bb.angle_phi; npPlot1.Label = "Phi"; npPlot1.Color = System.Drawing.Color.Blue; npSurface.Add(npPlot1, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left); //Phi: npPlot2.AbscissaData = bb.time; npPlot2.DataSource = bb.angle_psi; npPlot2.Label = "Psi"; npPlot2.Color = System.Drawing.Color.Red; npSurface.Add(npPlot2, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left); //Theta: npPlot3.AbscissaData = bb.time; npPlot3.DataSource = bb.angle_theta; npPlot3.Label = "Theta"; npPlot3.Color = System.Drawing.Color.Green; npSurface.Add(npPlot3, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left); //Speed: npPlot4.AbscissaData = bb.time; npPlot4.DataSource = bb.SpeedVsTheta; npPlot4.Label = "Speed"; npPlot4.Color = System.Drawing.Color.Black; npSurface.Add(npPlot4, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left); ////Alti: //npPlot5.AbscissaData = bb.time; //npPlot5.DataSource = bb.altitude; //npPlot5.Label = "Alt"; //npPlot5.Color = System.Drawing.Color.Orange; //npSurface.Add(npPlot5, NPlot.PlotSurface2D.XAxisPosition.Bottom, // NPlot.PlotSurface2D.YAxisPosition.Left); npSurface.Refresh(); MemoryStream memStream = new MemoryStream(); npSurface.Bitmap.Save(memStream, System.Drawing.Imaging.ImageFormat.Gif); FileStream fs = new FileStream(@"D:\file.gif", FileMode.Create); memStream.WriteTo(fs); //Console.WriteLine("Done"); //Console.ReadLine(); }