Ejemplo n.º 1
0
        public void Test_Scatter_Smooth()
        {
            double[] xs  = { 18.5, 20.6, 22.3, 24.5, 26.6, 15, 15 };
            double[] ys  = { 1.43, 1.48, 1.6, 1.59, 1.53, 1.52, 1.6 };
            var      plt = new ScottPlot.Plot(600, 400);

            var sp1 = plt.AddScatter(xs, ys, label: "DrawLines()");

            sp1.Smooth = false;

            var sp2 = plt.AddScatter(xs, ys, label: "DrawCurve()");

            sp2.Smooth = true;

            plt.Legend();
            plt.SetAxisLimits(0, 30, 1.42, 1.62);
            TestTools.SaveFig(plt);
        }
Ejemplo n.º 2
0
        public void Test_Benchmark_Toggle()
        {
            var plt = new ScottPlot.Plot(600, 400);

            plt.PlotSignal(DataGen.Sin(51));

            var meanDefault = TestTools.MeanPixel(plt.GetBitmap());

            plt.Benchmark(toggle: true);
            var meanBenchOn = TestTools.MeanPixel(plt.GetBitmap());

            plt.Benchmark(toggle: true);
            var meanBenchOff = TestTools.MeanPixel(plt.GetBitmap());

            // appearance of the benchmark will lessen mean pixel intensity
            Assert.AreEqual(meanDefault.R, meanBenchOff.R);
            Assert.Less(meanBenchOn.R, meanDefault.R);
        }
Ejemplo n.º 3
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.XAxis.Ticks(false);
            plt.YAxis.Ticks(false);
            plt.AxisAuto(0);
            plt.Frameless();

            TestTools.SaveFig(plt);
        }
Ejemplo n.º 4
0
        public void Test_Scatter_ChangeOnlyYErrorData()
        {
            var plt = new ScottPlot.Plot();

            // set errorY but NOT errorX
            double[] xs   = { 1, 2, 3, 4 };
            double[] ys   = { 1, 4, 9, 16 };
            double[] yErr = { .5, .5, 1, 1 };
            var      splt = new ScatterPlot(xs, ys, errorY: yErr)
            {
            };

            plt.Add(splt);
            var bmp = TestTools.GetLowQualityBitmap(plt);

            Console.WriteLine(new MeanPixel(bmp));

            Assert.That(bmp != null);
        }
Ejemplo n.º 5
0
        public void Test_AxisLine_FarAwayExpandXY()
        {
            Random rand = new Random(0);

            var plt  = new ScottPlot.Plot();
            var data = DataGen.RandomWalk(rand, 100);

            var sig = plt.AddSignal(data);

            sig.OffsetX = 100;
            sig.OffsetY = 100;
            sig.Label   = "scatter";

            plt.AddVerticalLine(-100, label: "vertical");
            plt.AddHorizontalLine(-100, label: "horizontal");
            plt.Legend();

            TestTools.SaveFig(plt);
        }
Ejemplo n.º 6
0
        public void Test_DataBackground_ColorCanBeSet()
        {
            var plt = new ScottPlot.Plot(600, 400);

            plt.PlotSignal(DataGen.Sin(51));

            var mean1 = TestTools.MeanPixel(plt.GetBitmap());

            plt.Style(dataBg: Color.Blue);
            var mean2 = TestTools.MeanPixel(plt.GetBitmap());

            //TestTools.SaveFig(plt);

            // we made the background white->blue, meaning we preserved blue while reducing red and green
            Assert.AreEqual(mean2.A, mean1.A);
            Assert.Less(mean2.R, mean1.R);
            Assert.Less(mean2.G, mean1.G);
            Assert.AreEqual(mean2.B, mean1.B);
        }
Ejemplo n.º 7
0
        public void Test_Remove_RemovesSinglePlot()
        {
            var plt = new ScottPlot.Plot();

            Random rand = new Random(0);
            var    barX = plt.AddPoint(111, 222);
            var    sigA = plt.AddSignal(DataGen.RandomWalk(rand, 100));
            var    sigB = plt.AddSignal(DataGen.RandomWalk(rand, 100));
            var    sigC = plt.AddSignal(DataGen.RandomWalk(rand, 100));
            var    sigD = plt.AddSignal(DataGen.RandomWalk(rand, 100));
            var    sigE = plt.AddSignal(DataGen.RandomWalk(rand, 100));
            var    barY = plt.AddPoint(111, 222);

            sigC.Label = "C";

            Assert.AreEqual(",,,C,,,", GetLegendLabels(plt));
            plt.Remove(sigC);
            Assert.AreEqual(",,,,,", GetLegendLabels(plt));
        }
Ejemplo n.º 8
0
        public void Test_AutomaticTicks_AdditionalTicksAppear()
        {
            var plt = new ScottPlot.Plot(400, 300);

            plt.AddSignal(ScottPlot.DataGen.Sin(51));

            // tick positions are automatic by default
            string originalTicks = TestTools.GetXTickString(plt);

            // set additional positions
            double[] positions = { -100, 15, 25, 35, 1234 };
            string[] labels    = { "x", "a", "b", "c", "y" };
            plt.XAxis.AutomaticTickPositions(positions, labels);
            Assert.AreNotEqual(originalTicks, TestTools.GetXTickString(plt));

            // reset to automatic ticks
            plt.XAxis.AutomaticTickPositions();
            Assert.AreEqual(originalTicks, TestTools.GetXTickString(plt));
        }
Ejemplo n.º 9
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");
        }
Ejemplo n.º 10
0
        public void Test_Layout()
        {
            int pointCount = 50;

            double[] dataXs  = DataGen.Consecutive(pointCount);
            double[] dataSin = DataGen.Sin(pointCount);
            double[] dataCos = DataGen.Cos(pointCount);

            var plt = new ScottPlot.Plot();

            plt.PlotScatter(dataXs, dataSin);
            plt.PlotScatter(dataXs, dataCos);

            plt.Title("Very Complicated Data");
            plt.XLabel("Experiment Duration");
            plt.YLabel("Productivity");

            TestTools.SaveFig(plt);
        }
Ejemplo n.º 11
0
        private void DrawGraph()
        {
            if (radSelectDate.Checked)
            {
                //SummaryList = SummaryList.Select(e => e.DateTime).Distinct().ToList();
                var plt = new ScottPlot.Plot(600, 400);


                // generate random data to plot
                string[] groupNames = SummaryList.Select(a => a.DateTime.ToString("HH:mm")).ToArray();

                int groupCount = groupNames.Length;

                var ys1 = SummaryList.Where(a => a.DateTime.Year == datePickerSelectDate.Value.Year &&
                                            a.DateTime.Month == datePickerSelectDate.Value.Month &&
                                            a.DateTime.Day == datePickerSelectDate.Value.Day)
                          .Select(a => decimal.ToDouble(a.CarwashTotalCost));

                var ys2 = SummaryList.Where(a => a.DateTime.Year == datePickerSelectDate.Value.Year &&
                                            a.DateTime.Month == datePickerSelectDate.Value.Month &&
                                            a.DateTime.Day == datePickerSelectDate.Value.Day)
                          .Select(a => decimal.ToDouble(a.BackToZeroTotalCost));

                var ys3 = SummaryList.Where(a => a.DateTime.Year == datePickerSelectDate.Value.Year &&
                                            a.DateTime.Month == datePickerSelectDate.Value.Month &&
                                            a.DateTime.Day == datePickerSelectDate.Value.Day)
                          .Select(a => decimal.ToDouble(a.DetailingTotalCost));

                var ys4 = SummaryList.Where(a => a.DateTime.Year == datePickerSelectDate.Value.Year &&
                                            a.DateTime.Month == datePickerSelectDate.Value.Month &&
                                            a.DateTime.Day == datePickerSelectDate.Value.Day)
                          .Select(a => decimal.ToDouble(a.PaintjobTotalCost));

                double[] values      = { ys1.FirstOrDefault(), ys2.FirstOrDefault(), ys3.FirstOrDefault(), ys4.FirstOrDefault() };
                string[] seriesNames = { ServiceTypeConstants.Carwash, ServiceTypeConstants.BackToZero, ServiceTypeConstants.Detailing, ServiceTypeConstants.PaintJob };

                formsPlot1.plt.PlotPie(values, seriesNames, showPercentages: true, showValues: true, showLabels: true, label: "Total Cost Pie Graph");
                formsPlot1.plt.Legend();


                formsPlot1.Render();
            }
        }
Ejemplo n.º 12
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;
        }
Ejemplo n.º 13
0
        public void Test_ManualTicks_CanBeEnabledAndDisabled()
        {
            var plt = new ScottPlot.Plot(400, 300);

            plt.AddSignal(ScottPlot.DataGen.Sin(51));

            // tick positions are automatic by default
            string originalTicks = TestTools.GetXTickString(plt);

            // set manual positions
            double[] manualXs     = { -100, 15, 25, 35, 1234 };
            string[] manyalLabels = { "x", "a", "b", "c", "y" };
            plt.XAxis.ManualTickPositions(manualXs, manyalLabels);
            Assert.AreNotEqual(originalTicks, TestTools.GetXTickString(plt));

            // reset to automatic ticks
            plt.XAxis.AutomaticTickPositions();
            Assert.AreEqual(originalTicks, TestTools.GetXTickString(plt));
        }
Ejemplo n.º 14
0
        public void Test_AutoAxis_ExpandXY()
        {
            var plt = new ScottPlot.Plot();

            // small area
            plt.PlotLine(-5, -5, 5, 5);
            plt.AxisAuto();
            var limitsA = plt.GetAxisLimits();

            // large area
            plt.PlotLine(-99, -99, 99, 99);
            plt.AxisAuto();
            var limitsB = plt.GetAxisLimits();

            Assert.That(limitsB.XMin < limitsA.XMin);
            Assert.That(limitsB.XMax > limitsA.XMax);
            Assert.That(limitsB.YMin < limitsA.YMin);
            Assert.That(limitsB.YMax > limitsA.YMax);
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        public void Test_DefinedSpacing_DateTimeAxis()
        {
            int pointCount = 20;

            // create a series of dates
            double[] dates    = new double[pointCount];
            var      firstDay = new DateTime(2020, 1, 22);

            for (int i = 0; i < pointCount; i++)
            {
                dates[i] = firstDay.AddDays(i).ToOADate();
            }

            // simulate data for each date
            double[] values = new double[pointCount];
            Random   rand   = new Random(0);

            for (int i = 1; i < pointCount; i++)
            {
                values[i] = values[i - 1] + rand.NextDouble();
            }

            var pltDefault = new ScottPlot.Plot();

            pltDefault.Title("Default xSpacing");
            pltDefault.AddScatter(dates, values);
            pltDefault.XAxis.DateTimeFormat(true);

            var pltTest = new ScottPlot.Plot();

            pltTest.Title("xSpacing = 1 day");
            pltTest.AddScatter(dates, values);
            pltTest.XAxis.DateTimeFormat(true);
            pltTest.XAxis.TickLabelStyle(rotation: 45);
            pltTest.Layout(bottom: 60); // need extra height to accomodate rotated labels

            // force 1 tick per day on a DateTime axis
            pltTest.XAxis.ManualTickSpacing(1, ScottPlot.Ticks.DateTimeUnit.Day);

            //TestTools.SaveFig(pltDefault);
            //TestTools.SaveFig(pltTest);
        }
Ejemplo n.º 17
0
        public void Test_SMA_DoubleArray()
        {
            Random rand = new Random(0);

            double[] xs     = DataGen.Consecutive(150);
            double[] prices = DataGen.RandomWalk(rand, xs.Length, offset: 50);
            double[] sma20  = ScottPlot.Statistics.Finance.SMA(prices, 20);
            double[] sma50  = ScottPlot.Statistics.Finance.SMA(prices, 50);

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

            plt.PlotScatter(xs, prices, lineWidth: 0, label: "Price");
            plt.PlotScatter(xs, sma20, label: "20 day SMA", markerSize: 0, lineWidth: 2);
            plt.PlotScatter(xs, sma50, label: "50 day SMA", markerSize: 0, lineWidth: 2);

            plt.YLabel("Price");
            plt.XLabel("Days");
            plt.Legend();
            TestTools.SaveFig(plt);
        }
Ejemplo n.º 18
0
        public void Test_ScaleBar_FontBold()
        {
            // bold fonts are supported on all operating systems so only test on windows
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) == false)
            {
                return;
            }

            var plt = new ScottPlot.Plot();

            plt.AntiAlias(false, false, false);

            // create plot with generic scalebar settings
            plt.PlotSignal(DataGen.Sin(51));
            plt.PlotSignal(DataGen.Cos(51));
            var sb = new PlottableScaleBar()
            {
                Width           = 5,
                Height          = .25,
                VerticalLabel   = "5 V",
                HorizontalLabel = "250 ms"
            };

            plt.Add(sb);
            var bmp1 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true));

            // customize the scalebar
            sb.FontBold = true;
            var bmp2 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true));

            // measure what changed
            //TestTools.SaveFig(bmp1, "1");
            //TestTools.SaveFig(bmp2, "2");
            var before = new MeanPixel(bmp1);
            var after  = new MeanPixel(bmp2);

            Console.WriteLine($"Before: {before}");
            Console.WriteLine($"After: {after}");

            Assert.That(after.IsDarkerThan(before));
        }
Ejemplo n.º 19
0
        public void Test_Layout_LabelsWithLineBreaks()
        {
            int pointCount = 50;

            double[] dataXs  = DataGen.Consecutive(pointCount);
            double[] dataSin = DataGen.Sin(pointCount);
            double[] dataCos = DataGen.Cos(pointCount);

            var plt = new ScottPlot.Plot();

            plt.PlotScatter(dataXs, dataSin);
            plt.PlotScatter(dataXs, dataCos);

            string labelWithLineBreak = "Line One\nLine Two";

            plt.Title(labelWithLineBreak, fontSize: 30);
            plt.XLabel(labelWithLineBreak);
            plt.YLabel(labelWithLineBreak);

            TestTools.SaveFig(plt);
        }
Ejemplo n.º 20
0
        public void Test_Legend_ReverseOrder()
        {
            var plt1 = new ScottPlot.Plot();

            plt1.PlotSignal(DataGen.Sin(100), label: "sin");
            plt1.PlotSignal(DataGen.Cos(100), label: "cos");
            plt1.Legend();
            string hash1 = ScottPlot.Tools.BitmapHash(plt1.GetBitmap());

            var plt2 = new ScottPlot.Plot();

            plt2.PlotSignal(DataGen.Sin(100), label: "sin");
            plt2.PlotSignal(DataGen.Cos(100), label: "cos");
            plt2.Legend(reverseOrder: true);
            string hash2 = ScottPlot.Tools.BitmapHash(plt2.GetBitmap());

            TestTools.SaveFig(plt1, "standard");
            TestTools.SaveFig(plt2, "reversed");

            Assert.AreNotEqual(hash1, hash2);
        }
Ejemplo n.º 21
0
        public void Test_Scatter_ZoomWorksWithOnePoint()
        {
            // Tests a bug where plots with a single point (axis span 0) can't zoom
            // https://github.com/ScottPlot/ScottPlot/issues/768

            double[] dataX = { 42 };
            double[] dataY = { 303 };

            // create a scatter plot with a single point
            var plt = new ScottPlot.Plot(400, 300);

            plt.AddScatter(dataX, dataY);
            var bmp1 = TestTools.GetLowQualityBitmap(plt);

            // zoom in
            plt.AxisZoom(2, 2);
            var bmp2 = TestTools.GetLowQualityBitmap(plt);

            // ensure the bitmap changed
            Assert.AreNotEqual(ScottPlot.Tools.BitmapHash(bmp1), ScottPlot.Tools.BitmapHash(bmp2));
        }
Ejemplo n.º 22
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);
        }
Ejemplo n.º 23
0
    public static string SaveFig(ScottPlot.Plot plot)
    {
        var    stackTrace        = new System.Diagnostics.StackTrace();
        string callingMethodName = stackTrace.GetFrame(1) !.GetMethod() !.Name;
        string filename          = callingMethodName + ".png";
        string folder            = Path.GetFullPath("RenderTest");

        if (!Directory.Exists(folder))
        {
            Directory.CreateDirectory(folder);
        }
        string path = Path.Combine(folder, filename);

        var sw = System.Diagnostics.Stopwatch.StartNew();

        plot.SaveFig(path);
        sw.Stop();

        Console.WriteLine($"Saved in {sw.Elapsed.TotalMilliseconds:N3} ms");
        Console.WriteLine(path);
        return(path);
    }
Ejemplo n.º 24
0
        public void Test_AutoAxis_WorksAfterClear()
        {
            var plt = new ScottPlot.Plot();

            plt.PlotPoint(0.1, 0.1);
            plt.PlotPoint(-0.1, -0.1);
            plt.AxisAuto();
            plt.Render(); // force a render
            Assert.Greater(plt.GetAxisLimits().XMin, -5);

            plt.PlotPoint(999, 999);
            plt.PlotPoint(-999, -999);
            plt.AxisAuto();
            plt.Render(); // force a render
            Assert.Less(plt.GetAxisLimits().XMin, -800);

            plt.Clear();
            plt.PlotPoint(0.1, 0.1);
            plt.PlotPoint(-0.1, -0.1);
            plt.Render(); // force a render
            Assert.Greater(plt.GetAxisLimits().XMin, -5);
        }
        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");
        }
Ejemplo n.º 26
0
        public void Test_AxisLine_ChangesPosition()
        {
            var plt = new ScottPlot.Plot();

            // start with default settings
            var axLine = new HLine()
            {
                position = 1.23
            };

            plt.Add(axLine);
            var bmp1 = TestTools.GetLowQualityBitmap(plt);

            // change the plottable
            axLine.position += 1;
            var bmp2 = TestTools.GetLowQualityBitmap(plt);

            // measure what changed
            //TestTools.SaveFig(bmp1, "1");
            //TestTools.SaveFig(bmp2, "2");
            Assert.AreNotEqual(ScottPlot.Tools.BitmapHash(bmp1), ScottPlot.Tools.BitmapHash(bmp2));
        }
Ejemplo n.º 27
0
        public void Test_MultiAxis_AutoAxis()
        {
            double[] xs = { 1, 2, 3 };
            double[] ys = { 4, 5, 6 };

            var plt = new ScottPlot.Plot(400, 300);
            var sp  = plt.AddScatter(xs, ys);

            sp.YAxisIndex = 1;
            sp.XAxisIndex = 1;
            plt.Render();
            var limitsA = plt.GetAxisLimits(1, 1);

            xs[0] = 999;
            ys[0] = 999;
            plt.AxisAuto(0.05, .01, 1, 1);
            plt.Render();
            var limitsB = plt.GetAxisLimits(1, 1);

            Assert.Greater(limitsB.XMax, limitsA.XMax);
            Assert.Greater(limitsB.YMax, limitsA.YMax);
        }
Ejemplo n.º 28
0
        public void Test_Finance_AutoWidth()
        {
            var plt = new ScottPlot.Plot();

            plt.AntiAlias(false, false, false);

            // start with default settings
            var op = new PlottableOHLC()
            {
                Candle = true,
                ohlcs  = new OHLC[]
                {
                    // open, high, low, close, time, timeSpan
                    new OHLC(273, 275, 264, 265, 1, 1),
                    new OHLC(267, 276, 265, 274, 4, 1),
                    new OHLC(277, 280, 275, 278, 7, 1),
                    new OHLC(267, 276, 265, 274, 10, 1),
                }
            };

            plt.Add(op);
            var bmp1 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true));

            // change the plottable
            op.AutoWidth = true;
            var bmp2 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true));

            // measure what changed
            //TestTools.SaveFig(bmp1, "1");
            //TestTools.SaveFig(bmp2, "2");
            var before = new MeanPixel(bmp1);
            var after  = new MeanPixel(bmp2);

            Console.WriteLine($"Before: {before}");
            Console.WriteLine($"After: {after}");

            Assert.That(after.IsDarkerThan(before));
        }
Ejemplo n.º 29
0
        private ScottPlot.Plot TestColormap(Palette cset, int lineWidth, bool dark = false)
        {
            var plt = new ScottPlot.Plot(600, 400);

            for (int i = 0; i < cset.Count(); i++)
            {
                double[] ys  = DataGen.Sin(51, phase: -i / Math.PI / cset.Count());
                var      sig = plt.AddSignal(ys, color: cset.GetColor(i));
                sig.MarkerSize = 0;
                sig.LineWidth  = lineWidth;
            }

            if (dark)
            {
                plt.Style(Style.Gray1);
                plt.Style(darkColor, darkColor);
            }

            plt.Title($"Colorset '{cset.Name}' has {cset.Count()} colors");
            plt.AxisAuto(0);

            return(plt);
        }
Ejemplo n.º 30
0
        public void Test_Legend_Bitmap()
        {
            var plt = new ScottPlot.Plot(600, 400);

            plt.PlotScatter(DataGen.Consecutive(51), DataGen.Sin(51), label: "sin");
            plt.PlotScatter(DataGen.Consecutive(51), DataGen.Cos(51), label: "cos");

            // the legend Bitmap should have size
            var bmpLegend1 = plt.GetLegendBitmap();

            Assert.IsNotNull(bmpLegend1);
            Assert.Greater(bmpLegend1.Width, 0);
            Assert.Greater(bmpLegend1.Height, 0);

            // add a new line to the plot
            plt.PlotScatter(DataGen.Consecutive(51), DataGen.Consecutive(51), label: "test123");

            // the legend Bitmap should be bigger now
            var bmpLegend2 = plt.GetLegendBitmap();

            Assert.Greater(bmpLegend2.Height, bmpLegend1.Height);
            Assert.Greater(bmpLegend2.Width, bmpLegend1.Width);
        }