Example #1
0
        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 PopulationPlot(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.XAxis.TickLabelStyle(fontSize: 18);
            plt.YAxis.TickLabelStyle(fontSize: 18);

            // additional plot styling
            plt.XAxis2.Label(label: "Life Expectancy in 2007", size: 26);
            plt.YAxis.Label(label: "Age (years)", size: 18);
            plt.Legend(location: Alignment.LowerRight);
            plt.Grid(lineStyle: LineStyle.Dot);
            plt.XAxis.Grid(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");
        }
        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");
        }
Example #4
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;
        }
Example #5
0
        public void GenerateMultipleBoxAndWhiskers(List <List <ResultModel> > allResults, List <int> xValues, string plotTitle, string plotName = "results")
        {
            var plt = new ScottPlot.Plot(600, 400);

            var poulations = new ScottPlot.Statistics.Population[allResults.Count];
            var p          = 0;

            foreach (var results in allResults)
            {
                var ys = new double[results.Count];
                var i  = 0;
                foreach (var r in results)
                {
                    ys[i] = r.Fitness;
                    i++;
                }
                var pop = new ScottPlot.Statistics.Population(ys);
                poulations[p] = pop;
                p++;
            }

            var popSeries = new ScottPlot.Statistics.PopulationSeries(poulations);

            plt.PlotPopulations(popSeries, "scores");

            // improve the style of the plot
            plt.Title(plotTitle);
            plt.YLabel("Solution energy");

            var ticks = new string[xValues.Count];
            var j     = 0;

            foreach (var iterations in xValues)
            {
                ticks[j] = iterations.ToString();
                j++;
            }
            plt.XTicks(ticks);
            plt.Legend();
            plt.Grid(lineStyle: LineStyle.Dot, enableVertical: false);

            plt.SaveFig($"{plotName}.png");
        }
Example #6
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 PopulationPlot(plottableMultiSeries);

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

            plt.Add(customPlottable);
            plt.XTicks(labels: groupLabels);
            plt.XAxis.TickLabelStyle(fontSize: 18);
            plt.YAxis.TickLabelStyle(fontSize: 18);

            // additional plot styling
            plt.XAxis2.Label(label: "Life Expectancy", size: 26);
            plt.YAxis.Label(label: "Age (years)", size: 18);
            plt.Legend(location: Alignment.LowerRight);
            plt.Grid(lineStyle: LineStyle.Dot);
            plt.XAxis.Grid(false);

            TestTools.SaveFig(plt);
        }