Exemple #1
0
        public void Test_ScaleBar_FontColor()
        {
            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.FontColor = System.Drawing.Color.Blue;
            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.IsMoreBlueThan(before));
        }
Exemple #2
0
        public void Test_ScaleBar_LineWidth()
        {
            var plt = new ScottPlot.Plot();

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

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

            // customize the scalebar
            sb.LineWidth += 1;
            var bmp2 = TestTools.GetLowQualityBitmap(plt);

            // 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));
        }
Exemple #3
0
        public void Test_ScaleBar_Default()
        {
            var plt = new ScottPlot.Plot();

            plt.AntiAlias(false, false, false);

            // start plot without scalebar
            plt.PlotSignal(DataGen.Sin(51));
            plt.PlotSignal(DataGen.Cos(51));
            var bmp1 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true));

            // add a scalebar
            var sb = new PlottableScaleBar()
            {
                Width           = 5,
                Height          = .25,
                VerticalLabel   = "5 V",
                HorizontalLabel = "250 ms"
            };

            plt.Add(sb);
            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));
        }
Exemple #4
0
        public void Test_RGB_analysis()
        {
            Random rand = new Random(0);

            double[] ys = DataGen.RandomWalk(rand, 100);

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

            plt.Style(figBg: System.Drawing.Color.Gray, dataBg: System.Drawing.Color.Gray);

            plt.PlotSignal(ys, yOffset: 0, color: System.Drawing.Color.FromArgb(255, 0, 0), label: "red", lineWidth: 2);
            plt.PlotSignal(ys, yOffset: 1, color: System.Drawing.Color.FromArgb(0, 255, 0), label: "green", lineWidth: 3);
            plt.PlotSignal(ys, yOffset: 2, color: System.Drawing.Color.FromArgb(0, 0, 255), label: "blue", lineWidth: 4);
            plt.PlotSignal(ys, yOffset: 3, color: System.Drawing.Color.FromArgb(0, 0, 0), label: "black");
            plt.PlotSignal(ys, yOffset: 4, color: System.Drawing.Color.FromArgb(255, 255, 255), label: "white");
            plt.Legend();

            System.Drawing.Bitmap bmp = plt.Render();

            var means = MeanPixel(bmp);

            Console.WriteLine($"mean bitmap intensity (ARGB): {means.A}, {means.R}, {means.G}, {means.B}");
            // mean bitmap intensity (ARGB): 255, 123.4157, 124.8481, 126.327066666667

            Assert.AreEqual(means.A, 255);    // image is not transparent
            Assert.Greater(means.B, means.G); // blue line is thicker than green line
            Assert.Greater(means.G, means.R); // green line is thicker than red line
        }
Exemple #5
0
        public void Test_Scatter_Simple()
        {
            var plt = new ScottPlot.Plot(500, 300);

            plt.PlotSignal(DataGen.Sin(51), label: "sin");
            plt.PlotSignal(DataGen.Cos(51), label: "cos");
            plt.Legend();

            TestTools.SaveFig(plt);
        }
        public void Test_Axis_VeryBigNumbers()
        {
            var plt = new ScottPlot.Plot();

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

            plt.Axis(y1: -10e50, y2: 10e50);

            TestTools.SaveFig(plt);
        }
Exemple #7
0
        private ScottPlot.Plot GetDemoPlot()
        {
            Random rand = new Random(0);
            var    plt  = new ScottPlot.Plot();

            plt.PlotScatter(ScottPlot.DataGen.Random(rand, 100, 20), ScottPlot.DataGen.Random(rand, 100, 5, 3), label: "scatter1");
            plt.PlotSignal(ScottPlot.DataGen.RandomWalk(rand, 100), label: "signal1");
            plt.PlotScatter(ScottPlot.DataGen.Random(rand, 100), ScottPlot.DataGen.Random(rand, 100), label: "scatter2");
            plt.PlotSignal(ScottPlot.DataGen.RandomWalk(rand, 100), label: "signal2");
            plt.PlotVLine(43, lineWidth: 4, label: "vline");
            plt.PlotHLine(1.23, lineWidth: 4, label: "hline");
            plt.PlotText("ScottPlot", 50, 0.25, rotation: -45, fontSize: 36, label: "text");
            plt.Legend();
            return(plt);
        }
Exemple #8
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 #9
0
        public void Test_Remove_RemovesSinglePlot()
        {
            var plt = new ScottPlot.Plot();

            Random rand = new Random(0);
            var    barX = plt.AddPoint(111, 222, label: "X");
            var    sigA = plt.PlotSignal(DataGen.RandomWalk(rand, 100), label: "A");
            var    sigB = plt.PlotSignal(DataGen.RandomWalk(rand, 100), label: "B");
            var    sigC = plt.PlotSignal(DataGen.RandomWalk(rand, 100), label: "C");
            var    sigD = plt.PlotSignal(DataGen.RandomWalk(rand, 100), label: "D");
            var    sigE = plt.PlotSignal(DataGen.RandomWalk(rand, 100), label: "E");
            var    barY = plt.AddPoint(111, 222, label: "Y");

            Assert.AreEqual("X,A,B,C,D,E,Y", GetLegendLabels(plt));
            plt.Remove(sigC);
            Assert.AreEqual("X,A,B,D,E,Y", GetLegendLabels(plt));
        }
Exemple #10
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 #11
0
        public void Test_Remove_RemovesSinglePlot()
        {
            var plt = new ScottPlot.Plot();

            Random rand = new Random(0);
            var    barX = plt.PlotPoint(111, 222, label: "X");
            var    sigA = plt.PlotSignal(DataGen.RandomWalk(rand, 100), label: "A");
            var    sigB = plt.PlotSignal(DataGen.RandomWalk(rand, 100), label: "B");
            var    sigC = plt.PlotSignal(DataGen.RandomWalk(rand, 100), label: "C");
            var    sigD = plt.PlotSignal(DataGen.RandomWalk(rand, 100), label: "D");
            var    sigE = plt.PlotSignal(DataGen.RandomWalk(rand, 100), label: "E");
            var    barY = plt.PlotPoint(111, 222, label: "Y");

            Assert.AreEqual("X,A,B,C,D,E,Y", string.Join(",", plt.GetPlottables().Select(x => x.GetLegendItems()[0].label)));
            plt.Remove(sigC);
            Assert.AreEqual("X,A,B,D,E,Y", string.Join(",", plt.GetPlottables().Select(x => x.GetLegendItems()[0].label)));
        }
Exemple #12
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());

            Assert.AreNotEqual(hash1, hash2);
        }
Exemple #13
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));
        }
Exemple #14
0
        public void Test_FigureBackground_SupportsTransparency()
        {
            var plt = new ScottPlot.Plot(600, 400);

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

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

            plt.Style(figBg: Color.Transparent);
            var mean2 = TestTools.MeanPixel(plt.GetBitmap());

            Assert.Less(mean2.A, mean1.A);
        }
Exemple #15
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 #16
0
        public void Test_AxisLine_FarAwayExpandXY()
        {
            Random rand = new Random(0);

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

            plt.PlotSignal(data, xOffset: 100, yOffset: 100, label: "scatter");
            plt.PlotVLine(-100, label: "vertical");
            plt.PlotHLine(-100, label: "horizontal");
            plt.Legend();

            TestTools.SaveFig(plt);
        }
Exemple #17
0
        public void Test_FigureBackground_DefaultIsOpaqueWhite()
        {
            var plt = new ScottPlot.Plot(600, 400);

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

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

            plt.Style(figBg: Color.White);
            var mean2 = TestTools.MeanPixel(plt.GetBitmap());

            Assert.AreEqual(mean2.A, mean1.A);
            Assert.AreEqual(mean2.R, mean1.R);
            Assert.AreEqual(mean2.G, mean1.G);
            Assert.AreEqual(mean2.B, mean1.B);
        }
Exemple #18
0
        public void Test_FigureBackground_ColorCanBeSet()
        {
            var plt = new ScottPlot.Plot(600, 400);

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

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

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

            // 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);
        }
Exemple #19
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);
        }
Exemple #20
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 #21
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);
        }
Exemple #22
0
        private ScottPlot.Plot TestColormap(Colorset 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,
                                          //mult: 1 - .5 * i / cset.Count(),
                                          phase: -i / Math.PI / cset.Count());
                plt.PlotSignal(ys, color: cset.GetColor(i), markerSize: 0, 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);
        }