public static void PlotColormapCurves(Plot plt, Colormap cmap) { byte[] pixelValueRange = Enumerable.Range(0, 256).Select(x => (byte)x).ToArray(); double[] xs = pixelValueRange.Select(x => (double)x / 255).ToArray(); double[] rs = pixelValueRange.Select(x => (double)cmap.GetRGB(x).r).ToArray(); double[] gs = pixelValueRange.Select(x => (double)cmap.GetRGB(x).g).ToArray(); double[] bs = pixelValueRange.Select(x => (double)cmap.GetRGB(x).b).ToArray(); double[] ms = new double[pixelValueRange.Length]; for (int i = 0; i < ms.Length; i++) { ms[i] = (rs[i] + gs[i] + bs[i]) / 3.0; } plt.Clear(); plt.PlotScatter(xs, rs, Color.Red, markerSize: 0); plt.PlotScatter(xs, gs, Color.Green, markerSize: 0); plt.PlotScatter(xs, bs, Color.Blue, markerSize: 0); plt.PlotScatter(xs, ms, Color.Black, markerSize: 0, lineStyle: LineStyle.Dash); plt.AxisAuto(); plt.YLabel("Pixel Intensity"); plt.XLabel("Fractional Data Value"); }
public void ExecuteRecipe(Plot plt) { // create sample data double[] xs = { 1, 2, 3, 4 }; double[] ys1 = { 1, 3, 1, 2 }; double[] ys2 = { 3, 7, 3, 1 }; double[] ys3 = { 5, 2, 5, 6 }; // pad data to turn a line into a shaded region xs = Tools.Pad(xs, cloneEdges: true); ys1 = Tools.Pad(ys1); ys2 = Tools.Pad(ys2); ys3 = Tools.Pad(ys3); // plot the padded data points as polygons plt.AddPolygon(xs, ys3, plt.GetNextColor(.7), lineWidth: 2); plt.AddPolygon(xs, ys2, plt.GetNextColor(.7), lineWidth: 2); plt.AddPolygon(xs, ys1, plt.GetNextColor(.7), lineWidth: 2); // use tight margins so we don't see the edges of polygons plt.AxisAuto(0, 0); }
public void ExecuteRecipe(Plot plt) { Random rand = new(0); int pointCount = 30; double[] xs = DataGen.Consecutive(pointCount); double[] ys = DataGen.Random(rand, pointCount, 10); string[] labels = ys.Select(x => x.ToString("N2")).ToArray(); var labelFont = new Drawing.Font { Bold = true, Color = Color.Black, Alignment = Alignment.MiddleCenter }; var myBubblePlot = plt.AddBubblePlot(); for (int i = 0; i < xs.Length; i++) { // give each bubble a random size and make smaller ones bluer double randomValue = rand.NextDouble(); double bubbleSize = randomValue * 30 + 10; Color bubbleColor = Drawing.Colormap.Jet.GetColor(randomValue, .5); myBubblePlot.Add( x: xs[i], y: ys[i], radius: bubbleSize, fillColor: bubbleColor, edgeColor: Color.Transparent, edgeWidth: 1 ); plt.AddText(labels[i], xs[i], ys[i], labelFont); } plt.Title("Bubble Plot with Labels"); plt.AxisAuto(.2, .25); // zoom out to accommodate large bubbles }
public void Render(Plot plt) { var boxAndWiskers = new Statistics.BoxAndWhisker[3]; boxAndWiskers[0] = Statistics.BoxAndWhiskerFromData.OutlierQuartileMedian(Data.LineLengths.plot, 1); boxAndWiskers[1] = Statistics.BoxAndWhiskerFromData.OutlierQuartileMedian(Data.LineLengths.formsPlot, 2); boxAndWiskers[2] = Statistics.BoxAndWhiskerFromData.OutlierQuartileMedian(Data.LineLengths.wpfPlot, 3); // note: this is how to add experimental plottables (which don't have methods in the Plot module) PlottableBoxAndWhisker boxAndWhiskerPlot = new PlottableBoxAndWhisker(boxAndWiskers); List <Plottable> plottablesList = plt.GetPlottables(); plottablesList.Add(boxAndWhiskerPlot); plt.Title("Source Code Line Length"); plt.YLabel("Number of Characters"); double[] xPositions = { 1, 2, 3 }; string[] labels = { "Plot.cs", "FormsPlot.cs", "WpfPlot.cs" }; plt.XTicks(xPositions, labels); plt.AxisAuto(.3, .2); }
public void ExecuteRecipe(Plot plt) { double[] xs = DataGen.Consecutive(31); double[] ys = DataGen.Sin(31); var colormap = Drawing.Colormap.Viridis; var myBubblePlot = plt.AddBubblePlot(); for (int i = 0; i < xs.Length; i++) { double fraction = (double)i / xs.Length; myBubblePlot.Add( x: xs[i], y: ys[i], radius: 10 + i, fillColor: colormap.GetColor(fraction, alpha: .8), edgeColor: System.Drawing.Color.Black, edgeWidth: 2 ); } plt.Title("Advanced Bubble Plot"); plt.AxisAuto(.2, .25); // zoom out to accommodate large bubbles }
static async Task Main(string[] args) { IStockDataService yahooService = new YahooService(); _priceManager = new PriceManager(yahooService); var prices = CsvExtensions.ReadCsv( @"Data\\all_stocks_5yr.csv", new Dictionary <string, string> { { "date", "StartTime" }, { "open", "Open" }, { "close", "Close" }, { "high", "High" }, { "low", "Low" }, { "volume", "Volume" }, { "Name", "Symbol" } }); var aalPrice = prices.Where(c => c.Symbol.Equals("AAL")).SortByStartTime(); var open = aalPrice.Select(c => (double)c.Open).ToArray(); var high = aalPrice.Select(c => (double)c.High).ToArray(); var low = aalPrice.Select(c => (double)c.Low).ToArray(); var close = aalPrice.Select(c => (double)c.Close).ToArray(); var volume = aalPrice.Select(c => c.Volume).ToArray(); var lstm = new Lstm(open, high, low, close, volume); lstm.Print(); var scale = lstm.CalculateScale(); var min = lstm.CalculateMin(); var stochasticOsc = new StochasticOsc(); var sData = stochasticOsc.Run(GetData()); var plt = new Plot(600, 400); var slow = sData.Select(c => c.SlowValue).ToArray(); var vals = sData.Select(c => c.Value).ToArray(); //var xs = sData.Select(p => p.StartTime.ToOADate()).ToArray(); plt.PlotSignalXY(sData.Select(p => p.StartTime.ToOADate()).ToArray(), slow, label: "slow", color: Color.Red, lineWidth: 2, lineStyle: LineStyle.Solid, markerSize: 0); plt.PlotSignalXY(sData.Select(p => p.StartTime.ToOADate()).ToArray(), vals, label: "fast", color: Color.Black, lineWidth: 2, lineStyle: LineStyle.Solid); plt.Title("IBM Stochastic"); plt.YLabel("Stochastic Unit"); plt.XLabel("Date"); plt.Ticks(dateTimeX: true); //plt.Legend(); plt.AxisBounds(minY: 0, maxY: 100); plt.AxisAuto(verticalMargin: 0.01); plt.Add(new PlottableHLine(20, Color.Black, 1, "", false, 20, 20, LineStyle.Solid)); plt.Add(new PlottableHLine(80, Color.Black, 1, "", false, 80, 80, LineStyle.Solid)); plt.SaveFig("IBM Slow Stochastic Chart.png"); return; //var list = stochasticService.Run(sData); //await TargilAsync(); //var tickerManager = new TickerManager(yahooService, _priceManager); //var tickers = CsvExtensions.ReadConstituentsAsync("Data\\constituents.csv", new Dictionary<string, string> //{ // {"Symbol", "Symbol"}, // {"Name", "Name"}, // {"Sector", "Sector"}, //}).Result; //var msftTicker = tickerManager.GetTickerBySymbol(tickers, "MSFT"); //var prices = await _priceManager.GetPricesAsync( // msftTicker, // new DateTime(2020, 4, 13), // new DateTime(2020, 6, 26), // Interval.OneDay, // false); //var offsetPercent = 1; //var vals = stochasticService.Run(prices); //var plt = new ScottPlot.Plot(600, 400); //plt.PlotSignal(vals.Select(c => (double)c.Value).ToArray()); //plt.Title("Signal Plot Quickstart (5 million points)"); //plt.YLabel("Vertical Units"); //plt.XLabel("Horizontal Units"); //plt.SaveFig("Quickstart_Quickstart_Signal_5MillionPoints.png"); return; //var offsetPercent = 0.5; //var supportPoints = _priceManager.GetSupportExtremaGroups(prices, ExtremaType.Minimum, offsetPercent); //var p = prices.Last(); //Console.WriteLine($"Curret value: {p.Close}"); //Console.WriteLine("Support Points"); //supportPoints.Print(ExtremaType.Minimum); //Console.WriteLine(); //Console.WriteLine("Reject Points"); //rejectPoints.Print(ExtremaType.Maximum); //var daysMomentum = _priceManager.GetDaysMomentum(prices); //daysMomentum.Print(); }
public void Render(Plot plt) { GenericPlots.SinAndCos(plt); plt.AxisAuto(horizontalMargin: 0, verticalMargin: 0.5); }
public void Render(Plot plt) { GenericPlots.SinAndCos(plt); plt.AxisAuto(); }
private void BtnFitData_Click(object sender, EventArgs e) { plt.AxisAuto(); UpdateTextBoxesFromAxes(); }