public void Test_PlottablePopulations_Series()
        {
            // This example will display age, grouped by location.
            // This example has 1 series that contains 5 population objects.

            // for this example we will simulate countries by creating random data
            Random rand = new Random(0);

            var ages = new Population[]
            {
                new Population(rand, 54, 53, 5), // africa
                new Population(rand, 35, 72, 3), // americas
                new Population(rand, 48, 72, 4), // asia
                new Population(rand, 44, 78, 2), // europe
                new Population(rand, 14, 81, 1), // oceania
            };
            var customPlottable = new PlottablePopulations(ages, color: System.Drawing.Color.CornflowerBlue);

            // plot the multi-series
            var plt = new ScottPlot.Plot();

            plt.Add(customPlottable);
            plt.XTicks(labels: new string[] { "Africas", "Americas", "Asia", "Europe", "Oceania" });
            plt.Ticks(fontSize: 18);

            // additional plot styling
            plt.Title("Life Expectancy in 2007", fontSize: 26);
            plt.YLabel("Age (years)", fontSize: 18);
            plt.Legend(location: legendLocation.lowerRight);
            plt.Grid(lineStyle: LineStyle.Dot, enableVertical: false);

            TestTools.SaveFig(plt);
        }
        public void Test_PlottablePopulations_Population()
        {
            // This example will display a single population: mean age of every country in europe in 2007
            // This example has 1 series that contains 1 population.

            // for this example we will simulate countries by creating random data
            Random rand = new Random(0);
            var    ages = new Population(rand, 44, 78, 2);

            var customPlottable = new PlottablePopulations(ages);

            // plot the multi-series
            var plt = new ScottPlot.Plot(400, 300);

            plt.Add(customPlottable);
            plt.Ticks(displayTicksX: false);

            // additional plot styling
            plt.Title("Life Expectancy in European Countries in 2007");
            plt.YLabel("Age (years)");
            plt.Legend(location: legendLocation.lowerRight);
            plt.Grid(lineStyle: LineStyle.Dot, enableVertical: false);

            TestTools.SaveFig(plt);
        }
        public static void PlotMonthlyChange(List <MonthlyClosedDifference> series, string propertyName, string folderName, string fileName)
        {
            // get and convert specific property of a list of objects to array of doubles
            PropertyInfo prop = typeof(MonthlyClosedDifference).GetProperty(propertyName);

            double[] valSeries = series.Select(x => Convert.ToDouble(prop.GetValue(x))).ToArray();

            // months to x values and labels
            double[] x      = DataGen.Consecutive(series.Count());
            string[] labels = series.Select(x => x.Month).ToArray();

            var plt = new ScottPlot.Plot(1000, 700);

            plt.Title(propertyName, fontName: "Segoe UI Light", color: Color.Black);
            plt.Ticks(dateTimeX: false, fontName: "Cascadia Mono");
            plt.Grid(xSpacing: 1);

            // apply custom axis tick labels
            plt.XTicks(x, labels);

            // create folder if not exists
            System.IO.Directory.CreateDirectory(folderName);

            plt.PlotBar(x, valSeries, fillColor: Color.Orange);

            plt.SaveFig($"./{folderName}/{fileName}.png");
        }
        public static void PlotOHLC(List <StockHistoryDay> stockHistory, string folderName, string fileName)
        {
            List <ScottPlot.OHLC> valSeriesList = new List <ScottPlot.OHLC>();

            foreach (StockHistoryDay stockHistoryDay in stockHistory)
            {
                ScottPlot.OHLC ohlc = new ScottPlot.OHLC(
                    stockHistoryDay.Open,
                    stockHistoryDay.High,
                    stockHistoryDay.Low,
                    stockHistoryDay.Close,
                    stockHistoryDay.Date
                    );

                valSeriesList.Add(ohlc);
            }

            ScottPlot.OHLC[] valSeries = valSeriesList.ToArray();

            var plt = new ScottPlot.Plot(1000, 700);

            plt.Title("MSFT", fontName: "Segoe UI Light", color: Color.Black);
            plt.Ticks(dateTimeX: true, fontName: "Cascadia Mono");

            // grids at every 7 days
            plt.Grid(xSpacing: 7, xSpacingDateTimeUnit: ScottPlot.Config.DateTimeUnit.Day);
            plt.SetCulture(shortDatePattern: "M\\/dd");

            // create folder if not exists
            System.IO.Directory.CreateDirectory(folderName);

            plt.PlotOHLC(valSeries);

            plt.SaveFig($"./{folderName}/{fileName}.png");
        }
        static public void RunJolka(List <Solver <string> > backtracks, List <Solver <string> > backtrackfws, string heuristicB = "", string heuristicBF = "", string type = "")
        {
            var           plt     = new ScottPlot.Plot(1280, 720);
            List <double> xlist   = new List <double>();
            List <double> yfwlist = new List <double>();
            List <double> ylist   = new List <double>();

            foreach (var el in backtrackfws)
            {
                xlist.Add(el.solvedPuzzle.Puzzle.id);
                if (type == "time")
                {
                    yfwlist.Add(el.solvedPuzzle.elapsed.TotalMilliseconds);
                }
                else
                {
                    yfwlist.Add(el.solvedPuzzle.Puzzle.steps);
                }
            }
            foreach (var el in backtracks)
            {
                if (type == "time")
                {
                    ylist.Add(el.solvedPuzzle.elapsed.TotalMilliseconds);
                }
                else
                {
                    ylist.Add(el.solvedPuzzle.Puzzle.steps);
                }
            }
            double[] xs = xlist.ToArray();
            ylist.Insert(2, (double)1);
            double[] dataB  = Tools.Log10(ylist.ToArray());
            double[] dataBF = Tools.Log10(yfwlist.ToArray());
            plt.PlotBar(xs, dataB, label: "Backtrack w/ " + heuristicB, barWidth: .3, xOffset: -0.2, showValues: true);
            plt.PlotBar(xs, dataBF, label: "Backtrack with forward w/ " + heuristicBF, barWidth: .3, xOffset: 0.2, showValues: true);
            plt.Title(type + " over Jolka id");
            plt.Ticks(useExponentialNotation: false, useMultiplierNotation: false, logScaleY: true);
            plt.Axis(y1: 0);
            plt.XTicks(new string[] { "0", "1", "2", "3", "4" });
            if (type == "time")
            {
                plt.YLabel("Execution time [10 ^ y ms]");
            }
            else
            {
                plt.YLabel("Steps [10 ^ y]");
            }
            plt.XLabel("Jolka ID");
            plt.Legend(location: legendLocation.upperRight);
            plt.SaveFig(heuristicB + heuristicBF + type + "JolkaBvsBF" + ".png");
        }
Exemple #6
0
        public void Test_LargePlot_DateTimeAxis()
        {
            Random rand = new Random(0);

            double[] data     = DataGen.RandomWalk(rand, 100_000);
            DateTime firstDay = new DateTime(2020, 1, 1);

            var plt = new ScottPlot.Plot(4000, 400);

            plt.PlotSignal(data, sampleRate: 60 * 24, xOffset: firstDay.ToOADate());
            plt.Ticks(dateTimeX: true);

            TestTools.SaveFig(plt);
        }
Exemple #7
0
        public void Test_Layout_RotatedTicksWithRoom()
        {
            var plt = new ScottPlot.Plot(400, 300);

            plt.PlotSignal(DataGen.Sin(51), xOffset: 1e6);
            plt.PlotSignal(DataGen.Cos(51), xOffset: 1e6);

            // WARNING: this resets the layout, so you must call Layout() after this
            plt.XLabel("horizontal axis label");

            plt.Ticks(xTickRotation: 45);
            plt.Layout(xScaleHeight: 50);

            TestTools.SaveFig(plt);
        }
Exemple #8
0
        public void Test_PolygonVsScatter_Alignment()
        {
            double[] xs = { 75, 250, 280, 100 };
            double[] ys = { -100, -75, -200, -220 };

            var plt = new ScottPlot.Plot(320, 240);

            plt.PlotPolygon(xs, ys, fillColor: Color.LightGreen);
            plt.PlotLine(xs[0], ys[0], xs[1], ys[1], Color.Blue);
            plt.Grid(false);
            plt.Frame(false);
            plt.Ticks(false, false);
            plt.Title("Line/Scatter");

            TestTools.SaveFig(plt);
        }
Exemple #9
0
        public void Test_ScaleBar_Simple()
        {
            var plt = new ScottPlot.Plot(400, 300);

            plt.PlotSignal(DataGen.Sin(51));
            plt.PlotSignal(DataGen.Cos(51, mult: 1.5));

            plt.PlotScaleBar(5, .25, "5 ms", "250 pA");

            plt.Grid(false);
            plt.Frame(false);
            plt.Ticks(false, false);
            plt.AxisAuto(0);
            plt.LayoutFrameless();

            TestTools.SaveFig(plt);
        }
Exemple #10
0
        public void Test_tickFormat_timecode()
        {
            var plt = new ScottPlot.Plot(800, 300);

            // simulate 10 seconds of audio data
            int    pointsPerSecond = 44100;
            Random rand            = new Random(0);

            double[] ys = DataGen.RandomWalk(rand, pointsPerSecond * 10);

            // for DateTime compatibility, sample rate must be points/day
            double pointsPerDay = 24.0 * 60 * 60 * pointsPerSecond;

            plt.PlotSignal(ys, sampleRate: pointsPerDay);

            plt.Ticks(dateTimeX: true, dateTimeFormatStringX: "HH:mm:ss:fff");

            TestTools.SaveFig(plt);
        }
Exemple #11
0
        private string MakeGraph(string[] labels, double[] values)
        {

            double[] xs = DataGen.Consecutive(labels.Count());


            var plt = new ScottPlot.Plot(1920, 1080);
            plt.PlotBar(xs, values);

            // customize the plot to make it look nicer
            plt.Grid(enableVertical: false, lineStyle: LineStyle.Dot);
            plt.XTicks(xs, labels);
            plt.Ticks(fontSize: 25, xTickRotation: 45);
            plt.Layout(yScaleWidth: 80, titleHeight: 50, xLabelHeight: 200, y2LabelWidth: 20);
            string path = "graph.png";
            plt.SaveFig(path);

            return path;
        }
Exemple #12
0
        public void Test_PolygonVsSignal_AlignmentWithLargeValues()
        {
            double[] xs = { 1e6 + 75, 1e6 + 250, 1e6 + 280, 1e6 + 100 };
            double[] ys = { 1e6 - 100, 1e6 - 75, 1e6 - 200, 1e6 - 220 };

            var plt = new ScottPlot.Plot(320, 240);

            plt.PlotPolygon(xs, ys, fillColor: Color.LightGreen);
            plt.PlotSignal(
                ys: new double[] { ys[0], ys[1] },
                sampleRate: 1.0 / (xs[1] - xs[0]),
                xOffset: xs[0],
                color: Color.Blue,
                markerSize: 0
                );
            plt.Grid(false);
            plt.Frame(false);
            plt.Ticks(false, false);
            plt.Title("Large Value Signal");

            TestTools.SaveFig(plt);
        }
        static public void RunSudoku(double[] difficulty, double[] dataB, double[] dataBF, string heuristicB = "", string heuristicBF = "", string type = "")
        {
            var plt        = new ScottPlot.Plot(1280, 720);
            int pointCount = dataB.Length;

            plt.PlotBar(difficulty, dataB, label: "Backtrack w/ " + heuristicB, barWidth: .3, xOffset: -0.2);
            plt.PlotBar(difficulty, dataBF, label: "Backtrack with forward w/ " + heuristicBF, barWidth: .3, xOffset: 0.2);
            plt.Title("Average " + type + " over sudoku difficulty");
            plt.Axis(y1: 0);
            if (type == "time")
            {
                plt.YLabel("Execution time [ms]");
            }
            else
            {
                plt.YLabel("Steps");
            }
            plt.XLabel("Difficulty");
            plt.Legend(location: legendLocation.upperRight);
            plt.Ticks(useExponentialNotation: false, useMultiplierNotation: false);
            plt.SaveFig(heuristicB + heuristicBF + type + "BvsBF" + ".png");
        }
Exemple #14
0
        public static void SetStyle(Plot existingPlot, Style style)
        {
            switch (style)
            {
            case (Style.Black):
                existingPlot.Style(
                    figBg: Color.Black,
                    dataBg: Color.Black,
                    grid: ColorTranslator.FromHtml("#2d2d2d"),
                    tick: ColorTranslator.FromHtml("#757575"),
                    label: ColorTranslator.FromHtml("#b9b9ba"),
                    title: ColorTranslator.FromHtml("#FFFFFF")
                    );
                break;

            case (Style.Blue1):
                existingPlot.Style(
                    figBg: ColorTranslator.FromHtml("#07263b"),
                    dataBg: ColorTranslator.FromHtml("#0b3049"),
                    grid: ColorTranslator.FromHtml("#0e3d54"),
                    tick: ColorTranslator.FromHtml("#145665"),
                    label: ColorTranslator.FromHtml("#b5bec5"),
                    title: ColorTranslator.FromHtml("#d0dae2")
                    );
                break;

            case (Style.Blue2):
                existingPlot.Style(
                    figBg: ColorTranslator.FromHtml("#1b2138"),
                    dataBg: ColorTranslator.FromHtml("#252c48"),
                    grid: ColorTranslator.FromHtml("#2c334e"),
                    tick: ColorTranslator.FromHtml("#bbbdc4"),
                    label: ColorTranslator.FromHtml("#bbbdc4"),
                    title: ColorTranslator.FromHtml("#d8dbe3")
                    );
                break;

            case (Style.Blue3):
                existingPlot.Style(
                    figBg: ColorTranslator.FromHtml("#001021"),
                    dataBg: ColorTranslator.FromHtml("#021d38"),
                    grid: ColorTranslator.FromHtml("#273c51"),
                    tick: ColorTranslator.FromHtml("#d3d3d3"),
                    label: ColorTranslator.FromHtml("#d3d3d3"),
                    title: ColorTranslator.FromHtml("#FFFFFF")
                    );
                break;

            case (Style.Gray1):
                existingPlot.Style(
                    figBg: ColorTranslator.FromHtml("#31363a"),
                    dataBg: ColorTranslator.FromHtml("#3a4149"),
                    grid: ColorTranslator.FromHtml("#444b52"),
                    tick: ColorTranslator.FromHtml("#757a80"),
                    label: ColorTranslator.FromHtml("#d6d7d8"),
                    title: ColorTranslator.FromHtml("#FFFFFF")
                    );
                break;

            case (Style.Gray2):
                existingPlot.Style(
                    figBg: ColorTranslator.FromHtml("#131519"),
                    dataBg: ColorTranslator.FromHtml("#262626"),
                    grid: ColorTranslator.FromHtml("#2d2d2d"),
                    tick: ColorTranslator.FromHtml("#757575"),
                    label: ColorTranslator.FromHtml("#b9b9ba"),
                    title: ColorTranslator.FromHtml("#FFFFFF")
                    );
                break;

            case (Style.Light1):
                existingPlot.Style(
                    figBg: ColorTranslator.FromHtml("#FFFFFF"),
                    dataBg: ColorTranslator.FromHtml("#FFFFFF"),
                    grid: ColorTranslator.FromHtml("#ededed "),
                    tick: ColorTranslator.FromHtml("#7f7f7f"),
                    label: ColorTranslator.FromHtml("#000000"),
                    title: ColorTranslator.FromHtml("#000000")
                    );
                break;

            case (Style.Light2):
                existingPlot.Style(
                    figBg: ColorTranslator.FromHtml("#e4e6ec"),
                    dataBg: ColorTranslator.FromHtml("#f1f3f7"),
                    grid: ColorTranslator.FromHtml("#e5e7ea"),
                    tick: ColorTranslator.FromHtml("#77787b"),
                    label: ColorTranslator.FromHtml("#000000"),
                    title: ColorTranslator.FromHtml("#000000")
                    );
                break;

            case (Style.Control):
                existingPlot.Style(
                    figBg: SystemColors.Control,
                    dataBg: Color.White,
                    grid: Color.LightGray,
                    tick: Color.Black,
                    label: Color.Black,
                    title: Color.Black
                    );
                break;

            case (Style.Seaborn):
                existingPlot.Style(
                    figBg: Color.White,
                    dataBg: ColorTranslator.FromHtml("#eaeaf2"),
                    grid: Color.White,
                    tick: ColorTranslator.FromHtml("#AAAAAA"),
                    label: Color.Black,
                    title: Color.Black
                    );
                existingPlot.Frame(false);
                existingPlot.Ticks(displayTicksXminor: false, displayTicksYminor: false);
                break;

            default:
                existingPlot.Style(
                    figBg: Color.White,
                    dataBg: Color.White,
                    grid: Color.LightGray,
                    tick: Color.Black,
                    label: Color.Black,
                    title: Color.Black
                    );
                break;
            }
        }
Exemple #15
0
        public void Test_PlottablePopulations_MultiSeries()
        {
            // This example will display age, grouped by location, and by year.
            // This example has 3 series (years), each of which has 5 population objects (locations).

            // for this example we will simulate countries by creating random data
            Random rand = new Random(0);

            // start by collecting series data as Population[] arrays
            var ages1957 = new Population[]
            {
                new Population(rand, 54, 42, 4), // africa
                new Population(rand, 35, 56, 6), // americas
                new Population(rand, 48, 47, 5), // asia
                new Population(rand, 44, 66, 2), // europe
                new Population(rand, 14, 70, 1), // oceania
            };

            var ages1987 = new Population[]
            {
                new Population(rand, 54, 52, 8), // africa
                new Population(rand, 35, 70, 3), // americas
                new Population(rand, 48, 66, 3), // asia
                new Population(rand, 44, 75, 2), // europe
                new Population(rand, 14, 75, 1), // oceania
            };

            var ages2007 = new Population[]
            {
                new Population(rand, 54, 53, 5), // africa
                new Population(rand, 35, 72, 3), // americas
                new Population(rand, 48, 72, 4), // asia
                new Population(rand, 44, 78, 2), // europe
                new Population(rand, 14, 81, 1), // oceania
            };

            // now create a PopulationSeries object for each series
            string[] groupLabels = new string[] { "Africa", "Americas", "Asia", "Europe", "Oceania" };
            var      series1957  = new PopulationSeries(ages1957, "1957", color: System.Drawing.Color.Red);
            var      series1987  = new PopulationSeries(ages1987, "1987", color: System.Drawing.Color.Green);
            var      series2007  = new PopulationSeries(ages2007, "2007", color: System.Drawing.Color.Blue);

            // now collect all the series into a MultiSeries
            var multiSeries          = new PopulationSeries[] { series1957, series1987, series2007 };
            var plottableMultiSeries = new PopulationMultiSeries(multiSeries);
            var customPlottable      = new PlottablePopulations(plottableMultiSeries);

            // plot the multi-series
            var plt = new ScottPlot.Plot();

            plt.Add(customPlottable);
            plt.XTicks(labels: groupLabels);
            plt.Ticks(fontSize: 18);

            // additional plot styling
            plt.Title("Life Expectancy", fontSize: 26);
            plt.YLabel("Age (years)", fontSize: 18);
            plt.Legend(location: legendLocation.lowerRight);
            plt.Grid(lineStyle: LineStyle.Dot, enableVertical: false);

            TestTools.SaveFig(plt);
        }
Exemple #16
0
        public static string chart(string pair)
        {
            List <string> pena = new List <string>();

            System.Net.WebClient wc1 = new System.Net.WebClient();
            int    sum_chart         = 150;
            double last_price        = 0;
            String link_Response     = wc1.DownloadString("https://www.binance.com/api/v1/klines?symbol=" + pair + "&interval=15m&limit=" + sum_chart);

            MatchCollection matchList = System.Text.RegularExpressions.Regex.Matches(link_Response, @"(\d+.\d+)|\d+\d+|\d");

            pena = matchList.Cast <Match>().Select(match => match.Value).ToList();
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

            int count      = 0;
            int count_draw = 0;

            //Оишбка в апи hbc в конце несколкьо нулей 0 0 0 0 0
            //введен костыль-переменная
            ScottPlot.OHLC[] ohlcs = new ScottPlot.OHLC[sum_chart];
            var plt = new ScottPlot.Plot(800, 400);

            for (int i = 0; i < sum_chart; i++)
            {
                double Open     = Convert.ToDouble(pena[count_draw + 1]);
                double High     = Convert.ToDouble(pena[count_draw + 2]);
                double Low      = Convert.ToDouble(pena[count_draw + 3]);
                double Close    = Convert.ToDouble(pena[count_draw + 4]);
                double Opentime = ((Convert.ToDouble(pena[count_draw])) / 1000) + (3600 * 3);

                ohlcs[count] = new ScottPlot.OHLC(Open, High, Low, Close, ConvertFromUnixTimestamp(Opentime), 1);
                count_draw   = count_draw + 12;
                count++;
                last_price = Close;
            }

            plt.Title("15 Minute Chart");
            plt.YLabel("Stock Price (" + pair + ")");
            plt.Ticks(dateTimeX: true, dateTimeFormatStringX: "HH:mm:ss", numericFormatStringY: "n");
            plt.PlotCandlestick(ohlcs);
            plt.Style(tick: Color.White, label: Color.White, title: Color.White, dataBg: Color.FromArgb(255, 36, 43, 60), grid: Color.FromArgb(255, 36, 43, 60), figBg: Color.FromArgb(255, 36, 43, 60));
            DateTime date1 = new DateTime();

            date1 = DateTime.Now;

            string name = "PlotTypes" + pair + "№" + date1.Ticks + ".png";

            string name_file  = name;
            string label_name = Convert.ToString(last_price);

            plt.PlotHLine(y: last_price, color: Color.Green, lineWidth: 0.5, label: label_name);
            plt.Legend(backColor: Color.FromArgb(255, 36, 43, 60), location: legendLocation.upperCenter);



            plt.SaveFig(name_file);



            return(name_file);
        }