Exemple #1
0
        public void Test_SignalLowDensity_FilledBelow()
        {
            Random rand = new(0);

            double[] values = ScottPlot.DataGen.Random(rand, pointCount: 10, offset: -.5);

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

            sig.Color      = ScottPlot.Drawing.GDI.Semitransparent(System.Drawing.Color.Red, .5);
            sig.MarkerSize = 0;
            sig.LineWidth  = 5;
            sig.FillBelow(System.Drawing.Color.Blue);
            sig.BaselineY = 0.2;

            TestTools.SaveFig(plt);
        }
        static public void Run(List <double[]> data, string label, double[] values)
        {
            var plt        = new ScottPlot.Plot(1280, 720);
            int pointCount = data[0].Length;

            for (int i = 0; i < data.Count; i++)
            {
                plt.PlotSignal(data[i], label: label + " = " + values[i].ToString());
            }

            plt.Title("Scores of each generation");
            plt.YLabel("Score");
            plt.XLabel("Iterations");
            plt.Ticks(useExponentialNotation: false, useMultiplierNotation: false);
            plt.Legend();
            plt.SaveFig(label + ".png");
        }
Exemple #3
0
        public void Test_AutoAxis_ScatterDiagonalLine()
        {
            var plt = new ScottPlot.Plot();

            plt.PlotScatter(
                xs: new double[] { 1, 2 },
                ys: new double[] { 1, 2 }
                );
            plt.AxisAuto();
            Console.WriteLine(plt.GetSettings().axes);

            Assert.IsTrue(plt.GetSettings().axes.x.span > 0);
            Assert.IsTrue(plt.GetSettings().axes.y.span > 0);

            //string name = System.Reflection.MethodBase.GetCurrentMethod().Name;
            //plt.SaveFig(System.IO.Path.GetFullPath(name + ".png"));
        }
Exemple #4
0
        public void Test_Pie_Center()
        {
            double[] values = { 778, 43, 283, 76, 184 };
            string[] labels = { "C#", "JAVA", "Python", "F#", "PHP" };

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

            plt.PlotPie(values, labels, showLabels: false);
            plt.Legend();

            plt.Grid(false);
            plt.Frame(false);
            plt.XAxis.Ticks(false);
            plt.YAxis.Ticks(false);

            TestTools.SaveFig(plt);
        }
Exemple #5
0
        public string Figure_08_Plotting_Text()
        {
            string name     = System.Reflection.MethodBase.GetCurrentMethod().Name.Replace("Figure_", "");
            string fileName = System.IO.Path.GetFullPath($"{outputFolderName}/{name}.png");

            var plt = new ScottPlot.Plot(width, height);

            plt.PlotScatter(dataXs, dataSin);
            plt.PlotScatter(dataXs, dataCos);
            plt.PlotPoint(25, 0.8);
            plt.PlotPoint(30, 0.3, color: Color.Magenta, markerSize: 15);
            plt.PlotText("important point", 25, 0.8);
            plt.PlotText("more important", 30, .3, fontSize: 16, bold: true);
            plt.SaveFig(fileName);
            Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}");
            return(name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap()));
        }
Exemple #6
0
        public void Test_OHLC_SetWidth()
        {
            var ohlcs = new ScottPlot.OHLC[]
            {
                // open, high, low, close, time, timeSpan
                new ScottPlot.OHLC(273, 275, 264, 265, 1, 1),
                new ScottPlot.OHLC(267, 276, 265, 274, 2.5, 2),
                new ScottPlot.OHLC(277, 280, 275, 278, 4, 1),
            };

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

            plt.Grid(false);
            plt.PlotOHLC(ohlcs, autoWidth: false);
            plt.SetAxisLimits(xMin: -1, xMax: 5);
            TestTools.SaveFig(plt);
        }
Exemple #7
0
        private void BtnLaunchRandomWalk_Click(object sender, EventArgs e)
        {
            int pointCount = (int)nudWalkPoints.Value;

            double[] randomWalkData = DataGen.RandomWalk(rand, pointCount);

            var plt = new ScottPlot.Plot();

            plt.AddSignal(randomWalkData);
            plt.Title($"{pointCount} Random Walk Points");

            var plotViewer = new ScottPlot.Eto.PlotViewForm(plt, 500, 300, "Random Walk Data");

            plotViewer.PlotView.Configuration.Quality = Control.QualityMode.High; // customize as desired
            plotViewer.Owner = this;                                              // so it closes if this window closes
            plotViewer.Show();                                                    // or ShowDialog() for a blocking window
        }
Exemple #8
0
        public void Test_CrossHair_Renders()
        {
            var plt = new ScottPlot.Plot(400, 300);

            plt.AddSignal(ScottPlot.DataGen.Sin(51));
            plt.AddSignal(ScottPlot.DataGen.Cos(51));
            plt.Title("Crosshair Demo");
            plt.XLabel("Horizontal Axis");
            plt.YLabel("Vertical Axis");

            plt.AddCrosshair(42, 0.45);

            // this is outside the data area so should not be rendered
            plt.AddCrosshair(-5, -1.2);

            TestTools.SaveFig(plt);
        }
Exemple #9
0
        static void TestPlotBasic()
        {
            int pointCount = 50;

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

            var plt = new ScottPlot.Plot();

            plt.PlotScatter(dataXs, dataSin);
            plt.PlotScatter(dataXs, dataCos);
            plt.Title("ScottPlot Quickstart");
            plt.XLabel("Time (seconds)");
            plt.YLabel("Potential (V)");
            plt.SaveFig("./Plots/01a_Quickstart.png");
        }
        private void btnLaunchRandomWalk_Click(object sender, EventArgs e)
        {
            int pointCount = (int)nudWalkPoints.Value;

            double[] randomWalkData = DataGen.RandomWalk(rand, pointCount);

            var plt = new ScottPlot.Plot();

            plt.PlotSignal(randomWalkData);
            plt.Title($"{pointCount} Random Walk Points");

            var plotViewer = new ScottPlot.FormsPlotViewer(plt, 500, 300, "Random Walk Data");

            plotViewer.Owner = this;                                         // so it closes if this window closes
            plotViewer.formsPlot1.Configure(lowQualityWhileDragging: false); // customize as desired
            plotViewer.Show();                                               // or ShowDialog() for a blocking window
        }
Exemple #11
0
        public void Test_DataContainsNan_Scatter()
        {
            double[] xs = new double[] { 1, double.NaN, 3, 4, 5, 6 };
            double[] ys = new double[] { 1, 4, 9, 16, double.NaN, 36 };

            var plt = new ScottPlot.Plot();

            plt.PlotScatter(xs, ys);
            plt.AxisAuto();
            plt.Axis(-2, 7, -10, 40);

            string name     = System.Reflection.MethodBase.GetCurrentMethod().Name;
            string filePath = System.IO.Path.GetFullPath(name + ".png");

            plt.SaveFig(filePath);
            Console.WriteLine($"Saved {filePath}");
        }
Exemple #12
0
        public void Test_Bar_ShowValuesHorizontal()
        {
            double[] xs  = { 1, 2, 3, 4, 5 };
            double[] ys1 = { 10, 15, 12, 6, 8, };
            double[] ys2 = { 6, 8, 8, 9, 5 };

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

            plt.PlotBar(xs, ys1, xOffset: -.20, barWidth: 0.3, showValues: true, label: "Series A", horizontal: true);
            plt.PlotBar(xs, ys2, xOffset: +.20, barWidth: 0.3, showValues: true, label: "Series B", horizontal: true);

            plt.Grid(lineStyle: ScottPlot.LineStyle.Dot);
            plt.XAxis.Grid(false);
            plt.Legend(location: ScottPlot.Alignment.UpperRight);
            plt.SetAxisLimits(xMin: 0);
            TestTools.SaveFig(plt);
        }
Exemple #13
0
        public void Test_AxisAutoX_Repeated()
        {
            double[] xs = { 1, 2, 3, 4, 5 };
            double[] ys = { 1, 4, 9, 16, 25 };

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

            plt.AddScatter(xs, ys);
            plt.SetAxisLimits(-5, 10, -15, 40);

            for (int i = 0; i < 10; i++)
            {
                plt.AxisAutoX();
            }

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

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

            string b64 = plt.GetImageBase64();

            Assert.Greater(b64.Length, 1000);

            string img = plt.GetImageHTML();

            Assert.Greater(img.Length, b64.Length);

            TestTools.SaveHtml(img);
        }
Exemple #15
0
        public void Test_GridLines_Disable()
        {
            var plt = new ScottPlot.Plot();

            plt.Grid(color: Color.White);
            var mean1 = TestTools.MeanPixel(plt.GetBitmap());

            // blue grid lines that aren't enabled should look the same as white grid lines
            plt.Grid(color: Color.Blue);
            plt.Grid(enable: false);
            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 #16
0
        public void Test_Bar_NegativeOnly()
        {
            var plt = new ScottPlot.Plot(600, 400);

            string[] labels   = { "one", "two", "three", "four", "five" };
            int      barCount = labels.Length;
            Random   rand     = new Random(0);

            double[] xs     = ScottPlot.DataGen.Consecutive(barCount);
            double[] ys     = ScottPlot.DataGen.RandomNormal(rand, barCount, -50, 10);
            double[] yError = ScottPlot.DataGen.RandomNormal(rand, barCount, 5, 2);

            plt.AddBar(xs, ys, yError);

            plt.XTicks(xs, labels);
            TestTools.SaveFig(plt);
        }
Exemple #17
0
        public void Test_Colormap_LayoutCanBeReset()
        {
            var plt = new ScottPlot.Plot(400, 300);

            plt.Style(figureBackground: System.Drawing.ColorTranslator.FromHtml("#dadada"));
            var bmpOriginal = new MeanPixel(plt.GetBitmap());

            var cb = plt.AddColorbar();
            var bmpWithColorbar = new MeanPixel(plt.GetBitmap());

            plt.Remove(cb);
            plt.YAxis2.ResetLayout();
            var bmpWithColorbarRemoved = new MeanPixel(plt.GetBitmap());

            Assert.AreNotEqual(bmpOriginal, bmpWithColorbar);
            Assert.AreEqual(bmpOriginal, bmpWithColorbarRemoved);
        }
Exemple #18
0
        public void Test_Annotation_Coordinates()
        {
            var plt = new ScottPlot.Plot(400, 300);

            // negative coordinates snap text to the lower or right edges
            plt.PlotAnnotation("Top Left", 10, 10);
            plt.PlotAnnotation("Lower Left", 10, -10);
            plt.PlotAnnotation("Top Right", -10, 10);
            plt.PlotAnnotation("Lower Right", -10, -10);

            // arguments allow customization of style
            plt.PlotAnnotation("Fancy Annotation", 10, 40,
                               fontSize: 24, fontName: "Impact", fontColor: Color.Red, shadow: true,
                               fill: true, fillColor: Color.White, fillAlpha: 1, lineWidth: 2);

            TestTools.SaveFig(plt);
        }
Exemple #19
0
        public void Test_FontName_IsSettable()
        {
            ScottPlot.Plot plt = TestTools.SamplePlotScatter();

            string font1 = ScottPlot.Config.Fonts.GetSerifFontName();
            string font2 = ScottPlot.Config.Fonts.GetMonospaceFontName();

            Assert.That(font1 != font2);

            plt.Title(sampleLabel, fontName: font1);
            string hash1 = TestTools.HashedFig(plt, font1);

            plt.Title(sampleLabel, fontName: font2);
            string hash2 = TestTools.HashedFig(plt, font2);

            Assert.That(hash1 != hash2);
        }
        public static void UpdatePackagePlots([TimerTrigger(OncePerDay)] TimerInfo myTimer, ILogger log)
        {
            string connectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage", EnvironmentVariableTarget.Process);
            CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(connectionString);

            // get all stats
            CloudTableClient tableClient = cloudStorageAccount.CreateCloudTableClient();
            CloudTable       statsTable  = tableClient.GetTableReference("packageStats");

            PackageStat[] allStats     = statsTable.CreateQuery <PackageStat>().ToArray().OrderBy(x => x.Timestamp).ToArray();
            string[]      packageNames = allStats.Select(x => x.Package).Distinct().ToArray();
            log.LogInformation($"Found {allStats.Length} total records.");
            log.LogInformation($"Identified {packageNames.Length} unique packages.");

            // create individual plots
            BlobServiceClient   blobServiceClient = new BlobServiceClient(connectionString);
            BlobContainerClient containerClient   = blobServiceClient.GetBlobContainerClient("$web");

            foreach (string packageName in packageNames)
            {
                // extract unique X/Y points for this package
                PackageStat[] stats = allStats.Where(x => x.Package == packageName).ToArray();
                SaveJsonStats(packageName, stats, containerClient);
                log.LogInformation($"Package {packageName} has {stats.Length} records.");
                double[] datetimes = stats.Select(x => x.Timestamp.DateTime.ToOADate()).ToArray();
                double[] downloads = stats.Select(x => (double)x.Downloads).ToArray();
                var(xs, ys) = UniquePoints(datetimes, downloads);

                // create the plot with ScottPlot
                var plt = new ScottPlot.Plot(600, 400);
                plt.Title(packageName);
                plt.YLabel("Downloads");
                plt.PlotStep(xs, ys, lineWidth: 2);
                plt.Ticks(dateTimeX: true);

                // Save the output as a Bitmap in blob storage
                string     filePath   = $"packagestats/{packageName}.png";
                BlobClient blobClient = containerClient.GetBlobClient(filePath);
                Bitmap     bmp        = plt.GetBitmap(true);
                using MemoryStream memoryStream = new MemoryStream();
                bmp.Save(memoryStream, ImageFormat.Png);
                memoryStream.Seek(0, SeekOrigin.Begin);
                blobClient.Upload(memoryStream, overwrite: true);
            }
        }
Exemple #21
0
        public void Test_PlotPolygon_PosAndNeg()
        {
            // generate sample data
            Random rand  = new Random(0);
            var    dataY = ScottPlot.DataGen.RandomWalk(rand, 1000, offset: -10);
            var    dataX = ScottPlot.DataGen.Consecutive(dataY.Length, spacing: 0.025);

            // create an array with an extra point on each side of the data
            double baseline = 0;
            var    xs       = new double[dataX.Length + 2];
            var    ys       = new double[dataY.Length + 2];

            Array.Copy(dataX, 0, xs, 1, dataX.Length);
            Array.Copy(dataY, 0, ys, 1, dataY.Length);
            xs[0]             = dataX[0];
            xs[xs.Length - 1] = dataX[dataX.Length - 1];
            ys[0]             = baseline;
            ys[ys.Length - 1] = baseline;

            // separate the data into two arrays (for positive and negative)
            double[] neg = new double[ys.Length];
            double[] pos = new double[ys.Length];
            for (int i = 0; i < ys.Length; i++)
            {
                if (ys[i] < 0)
                {
                    neg[i] = ys[i];
                }
                else
                {
                    pos[i] = ys[i];
                }
            }

            // now plot the arrays as polygons
            var plt = new ScottPlot.Plot();

            plt.PlotPolygon(xs, neg, "negative", lineWidth: 1,
                            lineColor: Color.Black, fillColor: Color.Red, fillAlpha: .5);
            plt.PlotPolygon(xs, pos, "positive", lineWidth: 1,
                            lineColor: Color.Black, fillColor: Color.Green, fillAlpha: .5);
            plt.Title("Shaded Line Plot (negative vs. positive)");
            plt.AxisAuto(0);
            TestTools.SaveFig(plt);
        }
Exemple #22
0
        public void Test_AxisAuto_SignalWithMinMaxIndexSet()
        {
            var plt = new ScottPlot.Plot(400, 300);
            var sig = plt.PlotSignal(ScottPlot.DataGen.Sin(1000), sampleRate: 10);

            sig.MinRenderIndex = 450;
            sig.MaxRenderIndex = 550;
            plt.AxisAuto();

            var limits = plt.GetAxisLimits();

            Console.WriteLine($"AutoAxis Limits: {limits}");

            Assert.Less(limits.XMin, limits.XMax);
            Assert.Less(limits.YMin, limits.YMax);

            TestTools.SaveFig(plt);
        }
Exemple #23
0
        public void Test_SmoothExample_PlotCurves()
        {
            var lsFolder = SampleData.GreenOverRed();

            double[] curve   = lsFolder.curveDeltaGoR;
            double[] curveXs = ScottPlot.DataGen.Consecutive(curve.Length);

            double[] curveSmooth   = ScanAGator.ImageDataTools.GaussianFilter1d(curve, lsFolder.filterPx);
            double[] curveSmoothXs = ScottPlot.DataGen.Consecutive(curveSmooth.Length);

            var plt = new ScottPlot.Plot();

            plt.PlotScatter(curveXs, curve, lineWidth: 0);
            plt.PlotScatter(curveSmoothXs, curveSmooth);
            plt.PlotVLine(lsFolder.filterPx * 2, Color.Red);
            plt.PlotVLine(curve.Length - lsFolder.filterPx * 2, Color.Red);
            SaveFigure(plt, "smooth_curve.png");
        }
Exemple #24
0
        public static void plot(float[] values, string saveFilePath, double sampleRateHz = 1, string title = null, string yLabel = null, string xLabel = null)
        {
            double[] values2 = new double[values.Length];
            for (int i = 0; i < values.Length; i++)
            {
                values2[i] = values[i];
            }

            var plt = new ScottPlot.Plot();

            plt.PlotSignal(values2, sampleRateHz, markerSize: 0);
            plt.Title(title);
            plt.YLabel(yLabel);
            plt.XLabel(xLabel);
            plt.AxisAuto(0);
            plt.SaveFig(saveFilePath);
            Console.WriteLine($"Saved: {System.IO.Path.GetFullPath(saveFilePath)}");
        }
Exemple #25
0
        public void Test_Plot_WidthAndHeight()
        {
            var plt = new ScottPlot.Plot(111, 222);

            Assert.AreEqual(111, plt.Width);
            Assert.AreEqual(222, plt.Height);

            plt.Resize(333, 444);
            Assert.AreEqual(333, plt.Width);
            Assert.AreEqual(444, plt.Height);

            plt.Width  = 123;
            plt.Height = 321;
            var bmp = plt.GetBitmap();

            Assert.AreEqual(123, bmp.Width);
            Assert.AreEqual(321, bmp.Height);
        }
Exemple #26
0
        public void Test_NotAllXsAscend_ThrowsException()
        {
            // generate random, NOT-ALL-ascending, unevenly-spaced data
            Random rand       = new Random(0);
            int    pointCount = 100_000;

            double[] ys = new double[pointCount];
            double[] xs = new double[pointCount];
            for (int i = 1; i < ys.Length; i++)
            {
                ys[i] = ys[i - 1] + rand.NextDouble() - .5;
                xs[i] = xs[i - 1] + rand.NextDouble() - .25; // may be <0
            }

            var plt = new ScottPlot.Plot(500, 350);

            Assert.Throws <ArgumentException>(() => { plt.PlotSignalXY(xs, ys); });
        }
Exemple #27
0
        public void Test_Frameless_HasNoFrame()
        {
            var plt = new ScottPlot.Plot(600, 400);

            plt.Style(figureBackground: System.Drawing.Color.Magenta);
            plt.Grid(false);
            plt.Frameless();

            plt.AddSignal(ScottPlot.DataGen.Sin(51), color: System.Drawing.Color.Gray);
            plt.Margins(0, 0);

            var bmp = TestTools.GetLowQualityBitmap(plt);

            TestTools.SaveFig(bmp);
            var after = new MeanPixel(bmp);

            Assert.That(after.IsGray());
        }
Exemple #28
0
        public void Test_PlotTicks_DateTime()
        {
            var plt = new ScottPlot.Plot();

            DateTime dt1 = new DateTime(2020, 1, 1);
            DateTime dt2 = new DateTime(2020, 12, 25);

            plt.SetAxisLimits(dt1.ToOADate(), dt2.ToOADate(), dt1.ToOADate(), dt2.ToOADate());
            plt.XLabel("Horizontal Axis Label");
            plt.YLabel("Vertical Axis Label");
            var before = new MeanPixel(plt);

            plt.Ticks(dateTimeX: true, dateTimeY: true);
            var after = new MeanPixel(plt);

            TestTools.SaveFig(plt);
            Assert.That(after.IsDifferentThan(before));
        }
Exemple #29
0
        public void Test_Radar_ZeroNorm()
        {
            // https://github.com/ScottPlot/ScottPlot/issues/1139

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

            double[,] values =
            {
                {  78, 83, 0, 76, 43 },
                { 100, 50, 0, 60, 90 }
            };

            double[] maxValues = { 100, 100, 0, 100, 100 };

            plt.AddRadar(values, independentAxes: true, maxValues: maxValues);

            TestTools.SaveFig(plt);
        }
Exemple #30
0
        public void Test_DocPlottables_CreateWithHelperMethodAndModify()
        {
            double[] xs = { 1, 2, 3, 4, 5 };
            double[] ys = { 1, 4, 9, 16, 25 };

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

            scatter.Color     = Color.Red;
            scatter.LineWidth = 2;

            TestTools.SaveFig(plt);

            string thisHash = ScottPlot.Tools.BitmapHash(plt.Render());

            createHash ??= thisHash;
            Assert.AreEqual(createHash, thisHash);
        }