Exemplo n.º 1
0
        public string Figure_07_Plotting_Points()
        {
            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.SaveFig(fileName);
            Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}");
            return(name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap()));
        }
Exemplo n.º 2
0
        public string Figure_01d_Zoom_and_Pan()
        {
            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.AxisZoom(2, 2);
            plt.AxisPan(-10, .5);
            plt.SaveFig(fileName);
            Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}");
            return(name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap()));
        }
Exemplo n.º 3
0
        public void TestGetBitmap()
        {
            {
                var    plt = new ScottPlot.Plot(1, 1);
                Bitmap bmp = plt.GetBitmap();
                Assert.AreEqual(bmp.Width, 1);
                Assert.AreEqual(bmp.Height, 1);
            }

            {
                var    plt = new ScottPlot.Plot(1, 1);
                Bitmap bmp = plt.GetBitmap(false, false);
                Assert.AreEqual(bmp.Width, 1);
                Assert.AreEqual(bmp.Height, 1);
            }
        }
Exemplo n.º 4
0
        public string Figure_26_Horizontal_Ticks_Only()
        {
            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.Grid(false);
            plt.Ticks(displayTicksY: false);
            plt.Frame(left: false, right: false, top: false);
            plt.SaveFig(fileName);
            Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}");
            return(name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap()));
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Will Plot and save Data to a file
        /// </summary>
        /// <param name="dat"></param>
        public static Bitmap PlotData(PlottableData[] dat, string xLab, string yLab)
        {
            var plt = new ScottPlot.Plot(355, 200);

            plt.XLabel(xLab);
            plt.YLabel(yLab);
            plt.Legend(true);
            foreach (var da in dat)
            {
                if (da.DataX.Length > 0)
                {
                    plt.PlotScatter(da.DataX, da.DataY, null, 1D, 5D, da.Label);
                }
            }
            return(plt.GetBitmap());
        }
Exemplo n.º 6
0
        public void Test_Plot_GetBitmap()
        {
            {
                var plt = new ScottPlot.Plot(321, 123);
                System.Drawing.Bitmap bmp = plt.GetBitmap();
                Assert.AreEqual(bmp.Width, 321);
                Assert.AreEqual(bmp.Height, 123);
            }

            {
                var plt = new ScottPlot.Plot(321, 123);
                System.Drawing.Bitmap bmp = plt.GetBitmap(false, false);
                Assert.AreEqual(bmp.Width, 321);
                Assert.AreEqual(bmp.Height, 123);
            }
        }
Exemplo n.º 7
0
        public Bitmap GetImage()
        {
            OpenFileDialog fileDlg = new OpenFileDialog();

            if (fileDlg.ShowDialog() == true)
            {
                using (WaveFileReader reader = new WaveFileReader(fileDlg.FileName))
                {
                    Assert.AreEqual(16, reader.WaveFormat.BitsPerSample, "Only works with 16 bit audio");
                    byte[]  buffer       = new byte[reader.Length];
                    int     read         = reader.Read(buffer, 0, buffer.Length);
                    Int16[] sampleBuffer = new Int16[read / 2];

                    Buffer.BlockCopy(buffer, 0, sampleBuffer, 0, read);

                    double[] audio = new double[read / 2];

                    int x = 0;
                    foreach (int i in sampleBuffer)
                    {
                        audio[x++] = (double)i;
                    }

                    var sampleRate = waveIn.WaveFormat.SampleRate;

                    // Window your signal
                    double[] window = FftSharp.Window.Hanning(audio.Length);
                    FftSharp.Window.ApplyInPlace(window, audio);

                    // create an array of audio sample times to aid plotting
                    double[] times = ScottPlot.DataGen.Consecutive(audio.Length, 1000d / sampleRate);

                    // plot the sample audio
                    var plt1 = new ScottPlot.Plot(800, 300);
                    plt1.PlotScatter(times, audio, markerSize: 1);
                    plt1.Title("Audio Signal");
                    plt1.YLabel("Amplitude");
                    plt1.XLabel("Time (ms)");
                    plt1.AxisAuto(0);


                    var bitmap = plt1.GetBitmap();
                    return(bitmap);
                }
            }
            return(null);
        }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
        public string Figure_59_StyleControl()
        {
            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, label: "sin");
            plt.PlotScatter(dataXs, dataCos, label: "cos");
            plt.Title("Very Complicated Data");
            plt.XLabel("Experiment Duration");
            plt.YLabel("Productivity");
            plt.Legend();
            plt.Style(ScottPlot.Style.Control);
            plt.SaveFig(fileName);
            Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}");
            return(name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap()));
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        private void MakeAPlot(double[,] data)
        {
            var plt = new ScottPlot.Plot(1000, 800);

            double[] x, y;
            int      linewidth = 2, markersize = 0;

            if (lorentzBtn.IsChecked == true)
            {
                double[] t = GetColumn(data, 0);
                x = GetColumn(data, 1);
                y = GetColumn(data, 3);
                plt.Title("Lorentz Attractor");
                plt.PlotScatter(x, y, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Red);
            }
            else if (jongBtn.IsChecked == true)
            {
                x          = GetColumn(data, 0);
                y          = GetColumn(data, 1);
                linewidth  = 0;
                markersize = 2;
                plt.Title("De jong Attractor");
                plt.PlotScatter(x, y, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Red);
            }
            else if (standardBtn.IsChecked == true)
            {
                x          = GetColumn(data, 0);
                y          = GetColumn(data, 1);
                linewidth  = 1;
                markersize = 0;
                plt.Title("Standard");
                plt.PlotScatter(x, y, markerSize: markersize, lineWidth: linewidth, color: System.Drawing.Color.Red);
            }


            plt.Legend();

            plt.XLabel(xlabel);
            plt.YLabel(ylabel);

            image1.Source = CreateBitmapSourceFromGdiBitmap(plt.GetBitmap());
        }
Exemplo n.º 12
0
        public string Figure_23_Frameless_Plot()
        {
            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);
            Color figureBgColor = ColorTranslator.FromHtml("#001021");
            Color dataBgColor   = ColorTranslator.FromHtml("#021d38");

            plt.Style(figBg: figureBgColor, dataBg: dataBgColor);
            plt.Grid(color: ColorTranslator.FromHtml("#273c51"));
            plt.Ticks(displayTicksX: false, displayTicksY: false);
            plt.Frame(drawFrame: false);
            plt.PlotScatter(dataXs, dataSin);
            plt.PlotScatter(dataXs, dataCos);
            plt.TightenLayout(padding: 0);
            plt.SaveFig(fileName);
            Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}");
            return(name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap()));
        }
Exemplo n.º 13
0
        public string Figure_61_Plot_Bar_Data()
        {
            string name     = System.Reflection.MethodBase.GetCurrentMethod().Name.Replace("Figure_", "");
            string fileName = System.IO.Path.GetFullPath($"{outputFolderName}/{name}.png");

            // create demo data to use for errorbars
            double[] yErr = new double[dataSin.Length];
            for (int i = 0; i < yErr.Length; i++)
            {
                yErr[i] = dataSin[i] / 5 + .025;
            }

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

            plt.Title("Bar Plot With Error Bars");
            plt.PlotBar(dataXs, dataSin, barWidth: .5, errorY: yErr, errorCapSize: 2);
            plt.SaveFig(fileName);
            Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}");
            return(name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap()));
        }
Exemplo n.º 14
0
        public string Figure_65_Histogram()
        {
            string name     = System.Reflection.MethodBase.GetCurrentMethod().Name.Replace("Figure_", "");
            string fileName = System.IO.Path.GetFullPath($"{outputFolderName}/{name}.png");

            Random rand = new Random(0);

            double[] values1 = ScottPlot.DataGen.RandomNormal(rand, pointCount: 1000, mean: 50, stdDev: 20);
            var      hist1   = new ScottPlot.Histogram(values1, min: 0, max: 100);

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

            plt.Title("Histogram");
            plt.YLabel("Count (#)");
            plt.XLabel("Value (units)");
            plt.PlotBar(hist1.bins, hist1.counts, barWidth: 1);
            plt.Axis(null, null, 0, null);
            plt.SaveFig(fileName);
            Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}");
            return(name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap()));
        }
Exemplo n.º 15
0
        public string Figure_22_Custom_Colors()
        {
            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);

            Color figureBgColor = ColorTranslator.FromHtml("#001021");
            Color dataBgColor   = ColorTranslator.FromHtml("#021d38");

            plt.Style(figBg: figureBgColor, dataBg: dataBgColor);
            plt.Grid(color: ColorTranslator.FromHtml("#273c51"));
            plt.Ticks(color: Color.LightGray);
            plt.PlotScatter(dataXs, dataSin);
            plt.PlotScatter(dataXs, dataCos);
            plt.Title("Very Complicated Data", Color.White);
            plt.XLabel("Experiment Duration", Color.LightGray);
            plt.YLabel("Productivity", Color.LightGray);
            plt.SaveFig(fileName);
            Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}");
            return(name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap()));
        }
Exemplo n.º 16
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // generate some data to plot
            int pointCount = 50;

            double[] dataXs  = new double[pointCount];
            double[] dataSin = new double[pointCount];
            double[] dataCos = new double[pointCount];
            for (int i = 0; i < pointCount; i++)
            {
                dataXs[i]  = i;
                dataSin[i] = Math.Sin(i * 2 * Math.PI / pointCount);
                dataCos[i] = Math.Cos(i * 2 * Math.PI / pointCount);
            }

            // create the scottPlot and render it onto a Canvas
            ScottPlot.Plot plt = new ScottPlot.Plot((int)canvasPlot.ActualWidth, (int)canvasPlot.ActualHeight);
            plt.PlotScatter(dataXs, dataSin);
            plt.PlotScatter(dataXs, dataCos);
            plt.AxisAuto();
            plt.Title("ScottPlot WPF Demo");
            imagePlot.Source = bmpImageFromBmp(plt.GetBitmap());
        }
Exemplo n.º 17
0
        public void TestGroup_PlotTypes(int width = 600, int height = 400, bool clearAfter = true)
        {
            plt = new ScottPlot.Plot(width, height);
            Test_AddPlot_Text();
            Test_AddPlot_Point();
            Test_AddPlot_Scatter();
            Test_AddPlot_Signal();
            Test_AddPlot_Vline();
            Test_AddPlot_Hline();
            plt.Title("title");
            plt.XLabel("horizontal");
            plt.YLabel("vertical");
            plt.Legend();

            Console.Write($"Rendering {plt.GetPlottables().Count} plots with {plt.GetTotalPoints()} points ... ");
            plt.GetBitmap();
            Pass();

            if (clearAfter)
            {
                ClearPlot();
            }
        }
Exemplo n.º 18
0
        public string Figure_62_Plot_Bar_Data_Fancy()
        {
            string name     = System.Reflection.MethodBase.GetCurrentMethod().Name.Replace("Figure_", "");
            string fileName = System.IO.Path.GetFullPath($"{outputFolderName}/{name}.png");

            // generate some more complex data
            Random rand       = new Random(0);
            int    pointCount = 10;

            double[] Xs     = new double[pointCount];
            double[] dataA  = new double[pointCount];
            double[] errorA = new double[pointCount];
            double[] XsB    = new double[pointCount];
            double[] dataB  = new double[pointCount];
            double[] errorB = new double[pointCount];
            for (int i = 0; i < pointCount; i++)
            {
                Xs[i]     = i * 10;
                dataA[i]  = rand.NextDouble() * 100;
                dataB[i]  = rand.NextDouble() * 100;
                errorA[i] = rand.NextDouble() * 10;
                errorB[i] = rand.NextDouble() * 10;
            }

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

            plt.Title("Multiple Bar Plots");
            plt.Grid(false);
            // we customize barWidth and xOffset to squeeze grouped bars together
            plt.PlotBar(Xs, dataA, errorY: errorA, label: "data A", barWidth: 3.2, xOffset: -2);
            plt.PlotBar(Xs, dataB, errorY: errorB, label: "data B", barWidth: 3.2, xOffset: 2);
            plt.Axis(null, null, 0, null);
            plt.Legend();
            plt.SaveFig(fileName);
            Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}");
            return(name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap()));
        }
Exemplo n.º 19
0
        public string Figure_10_Modifying_Plotted_Data()
        {
            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);

            // Even after an array is given to ScottPlot plotted, its contents
            // can be updated and they will be displayed at the next render.
            // This is epsecially useful to know for creating live data displays.
            for (int i = 10; i < 20; i++)
            {
                dataSin[i] = i / 10.0;
                dataCos[i] = 2 * i / 10.0;
            }

            plt.SaveFig(fileName);
            Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}");
            PrepareDataSmall(); // hide
            return(name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap()));
        }
Exemplo n.º 20
0
        public Bitmap FFT()
        {
            OpenFileDialog fileDlg = new OpenFileDialog();

            if (fileDlg.ShowDialog() == true)
            {
                using (WaveFileReader reader = new WaveFileReader(fileDlg.FileName))
                {
                    Assert.AreEqual(16, reader.WaveFormat.BitsPerSample, "Only works with 16 bit audio");
                    byte[]  buffer       = new byte[reader.Length];
                    int     read         = reader.Read(buffer, 0, buffer.Length);
                    Int16[] sampleBuffer = new Int16[read / 2];

                    Buffer.BlockCopy(buffer, 0, sampleBuffer, 0, read);

                    double[] audio;

                    var sampleRate = waveIn.WaveFormat.SampleRate;

                    if (!FftSharp.Transform.IsPowerOfTwo(sampleBuffer.Length))
                    {
                        int targetLength = 1;
                        while (targetLength < sampleBuffer.Length)
                        {
                            targetLength *= 2;
                        }

                        audio = new double[targetLength];

                        int x = 0;
                        foreach (int i in sampleBuffer)
                        {
                            audio[x++] = (double)i;
                        }

                        for (; x < targetLength; x++)
                        {
                            audio[x] = 0;
                        }
                    }
                    else
                    {
                        audio = new double[read / 2];

                        int x = 0;
                        foreach (int i in sampleBuffer)
                        {
                            audio[x++] = (double)i;
                        }
                    }

                    // Window your signal
                    double[] window = FftSharp.Window.Hanning(audio.Length);
                    FftSharp.Window.ApplyInPlace(window, audio);

                    // For audio we typically want the FFT amplitude (in dB)
                    double[] fftPower = FftSharp.Transform.FFTpower(audio);

                    // Create an array of frequencies for each point of the FFT
                    double[] freqs = FftSharp.Transform.FFTfreq(sampleRate, fftPower.Length);

                    // plot the FFT amplitude

                    var plt2 = new ScottPlot.Plot(800, 300);
                    plt2.PlotScatter(freqs, fftPower, markerSize: 1);
                    plt2.Title("Fast Fourier Transformation (FFT)");
                    plt2.YLabel("Power (dB)");
                    plt2.XLabel("Frequency (Hz)");
                    plt2.AxisAuto(0);

                    var bitmap = plt2.GetBitmap();
                    return(bitmap);
                }
            }
            return(null);
        }
Exemplo n.º 21
0
        public void Test_Plot_InvalidDimensionsThrow(int width, int height)
        {
            var plt = new ScottPlot.Plot();

            Assert.Throws <ArgumentException>(() => { plt.GetBitmap(width, height); });
        }