Exemplo n.º 1
0
        public void Test_ScaleBar_FontColor()
        {
            var plt = new ScottPlot.Plot();

            // create plot with generic scalebar settings
            plt.AddSignal(DataGen.Sin(51));
            plt.AddSignal(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.FontColor = System.Drawing.Color.Blue;
            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.IsMoreBlueThan(before));
        }
Exemplo n.º 2
0
        public void Test_ScaleBar_Default()
        {
            var plt = new ScottPlot.Plot();

            // start plot without scalebar
            plt.AddSignal(DataGen.Sin(51));
            plt.AddSignal(DataGen.Cos(51));
            var bmp1 = TestTools.GetLowQualityBitmap(plt);

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

            plt.Add(sb);
            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));
        }
Exemplo n.º 3
0
        public void Test_SaveFig_OutputScaling()
        {
            var plt = new ScottPlot.Plot();

            plt.AddSignal(DataGen.Sin(51), label: "sin");
            plt.AddSignal(DataGen.Cos(51), label: "cos");
            plt.Title("Scaled Figure Demo");
            plt.XLabel("Horizontal Axis");
            plt.YLabel("Vertical Axis");
            plt.Legend();

            System.Drawing.Bitmap bmpA = plt.Render(400, 300);
            Assert.AreEqual(400, bmpA.Width);
            Assert.AreEqual(300, bmpA.Height);

            System.Drawing.Bitmap bmpB = plt.Render(400, 300, scale: .5);
            Assert.AreEqual(200, bmpB.Width);
            Assert.AreEqual(150, bmpB.Height);

            System.Drawing.Bitmap bmpC = plt.Render(400, 300, scale: 2);
            Assert.AreEqual(800, bmpC.Width);
            Assert.AreEqual(600, bmpC.Height);

            System.Drawing.Bitmap bmpD = plt.Render(300, 400, scale: 2);
            Assert.AreEqual(600, bmpD.Width);
            Assert.AreEqual(800, bmpD.Height);

            System.Drawing.Bitmap legendNormal = plt.RenderLegend();
            System.Drawing.Bitmap legendBig    = plt.RenderLegend(scale: 2);
            Assert.Greater(legendBig.Width, legendNormal.Width);
            Assert.Greater(legendBig.Height, legendNormal.Height);
        }
Exemplo n.º 4
0
        public void Test_Axis_VeryBigNumbers()
        {
            var plt = new ScottPlot.Plot();

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

            plt.SetAxisLimits(yMin: -10e50, yMax: 10e50);

            TestTools.SaveFig(plt);
        }
Exemplo n.º 5
0
        private ScottPlot.Plot GetDemoPlot()
        {
            Random rand = new Random(0);
            var    plt  = new ScottPlot.Plot();

            plt.AddScatter(DataGen.Random(rand, 100, 20), DataGen.Random(rand, 100, 5, 3), label: "scatter1");
            plt.AddSignal(DataGen.RandomWalk(rand, 100), label: "signal1");
            plt.AddScatter(DataGen.Random(rand, 100), ScottPlot.DataGen.Random(rand, 100), label: "scatter2");
            plt.AddSignal(DataGen.RandomWalk(rand, 100), label: "signal2");
            plt.AddVerticalLine(43, width: 4, label: "vline");
            plt.AddHorizontalLine(1.23, width: 4, label: "hline");
            plt.AddText("ScottPlot", 50, 0.25);
            plt.Legend();
            return(plt);
        }
Exemplo n.º 6
0
        public void Test_Layout_RotatedTicksWithRoom()
        {
            var plt = new ScottPlot.Plot(400, 300);
            var s1  = plt.AddSignal(DataGen.Sin(51));
            var s2  = plt.AddSignal(DataGen.Cos(51));

            s1.OffsetX = 1e6;
            s2.OffsetX = 1e6;

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

            plt.XAxis.TickLabelStyle(rotation: 45);
            plt.Layout(bottom: 50);

            TestTools.SaveFig(plt);
        }
Exemplo n.º 7
0
        public void Test_ScaleBar_Simple()
        {
            var plt = new ScottPlot.Plot(400, 300);

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

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

            plt.Grid(false);
            plt.Frameless();
            plt.XAxis.Ticks(false);
            plt.YAxis.Ticks(false);
            plt.AxisAuto(0);
            plt.Frameless();

            TestTools.SaveFig(plt);
        }
Exemplo n.º 8
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));
        }
Exemplo n.º 9
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();

            // create plot with generic scalebar settings
            plt.AddSignal(DataGen.Sin(51));
            plt.AddSignal(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.FontBold = true;
            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));
        }
Exemplo n.º 10
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);
            var sig = plt.AddSignal(data, sampleRate: 60 * 24);

            sig.OffsetX = firstDay.ToOADate();

            plt.XAxis.DateTimeFormat(true);

            TestTools.SaveFig(plt);
        }
Exemplo n.º 11
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));
        }
Exemplo n.º 12
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));
        }
Exemplo n.º 13
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.AddSignal(ys, sampleRate: pointsPerDay);

            plt.XAxis.TickLabelFormat("HH:mm:ss:fff", true);

            TestTools.SaveFig(plt);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
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.AddPolygon(xs, ys, fillColor: Color.LightGreen);
            var sig = plt.AddSignal(
                ys: new double[] { ys[0], ys[1] },
                sampleRate: 1.0 / (xs[1] - xs[0]),
                color: Color.Blue);

            sig.MarkerSize = 0;
            sig.OffsetX    = xs[0];
            plt.Grid(false);
            plt.Frame(false);
            plt.XAxis.Ticks(false);
            plt.YAxis.Ticks(false);
            plt.Title("Large Value Signal");

            TestTools.SaveFig(plt);
        }