コード例 #1
0
ファイル: FormSettings.cs プロジェクト: csuffyy/ScottPlot
 private void UpdateTextBoxesFromAxes()
 {
     tbX1.Text = Math.Round(plt.Axis()[0], 4).ToString();
     tbX2.Text = Math.Round(plt.Axis()[1], 4).ToString();
     tbY1.Text = Math.Round(plt.Axis()[2], 4).ToString();
     tbY2.Text = Math.Round(plt.Axis()[3], 4).ToString();
 }
コード例 #2
0
ファイル: Bar.cs プロジェクト: pajek2111/ScottPlot
            public void Render(Plot plt)
            {
                // generate random data to plot
                Random rand       = new Random(0);
                int    pointCount = 10;

                double[] xs   = DataGen.Consecutive(pointCount);
                double[] ys1  = DataGen.RandomNormal(rand, pointCount, 20, 5);
                double[] ys2  = DataGen.RandomNormal(rand, pointCount, 20, 5);
                double[] err1 = DataGen.RandomNormal(rand, pointCount, 5, 2);
                double[] err2 = DataGen.RandomNormal(rand, pointCount, 5, 2);

                // add both bar plots with a careful widths and offsets
                plt.PlotBar(xs, ys1, err1, "data A", barWidth: .3, xOffset: -.2);
                plt.PlotBar(xs, ys2, err2, "data B", barWidth: .3, xOffset: .2);

                // customize the plot to make it look nicer
                plt.Axis(y1: 0);
                plt.Grid(enableVertical: false, lineStyle: LineStyle.Dot);
                plt.Axis(y1: 0);
                plt.Legend(location: legendLocation.upperRight);

                // apply custom axis tick labels
                string[] labels = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" };
                plt.XTicks(xs, labels);
            }
コード例 #3
0
ファイル: Bar.cs プロジェクト: zrolfs/ScottPlot
            public void Render(Plot plt)
            {
                // generate random data to plot
                Random rand       = new Random(0);
                int    pointCount = 10;

                double[] Xs     = new double[pointCount];
                double[] dataA  = new double[pointCount];
                double[] errorA = 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;
                }

                // add both bar plots with a careful widths and offsets
                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);

                // customize the plot to make it look nicer
                plt.Grid(false);
                plt.Axis(null, null, 0, null);
                plt.Legend();

                // apply custom axis tick labels
                string[] labels = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" };
                plt.XTicks(Xs, labels);
            }
コード例 #4
0
ファイル: Bar.cs プロジェクト: zrolfs/ScottPlot
            public void Render(Plot plt)
            {
                // generate random data to plot
                Random rand       = new Random(0);
                int    pointCount = 10;

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

                // make the bar plot
                plt.PlotBar(Xs, dataA, errorY: errorA);

                // customize the plot to make it look nicer
                plt.Axis(null, null, 0, null);
                plt.Grid(false);

                // apply custom axis tick labels
                string[] labels = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" };
                plt.XTicks(Xs, labels);
            }
コード例 #5
0
            public void Render(Plot plt)
            {
                // create some sample data
                double[] xs      = { 0 };
                double[] valuesA = { 0x40000000 };
                double[] valuesB = { 0x40100000 };
                double[] valuesC = { 0xA0000000 };

                // to simulate stacking B on A, shift B up by A
                double[] valuesB2 = new double[valuesB.Length];
                double[] valuesC2 = new double[valuesC.Length];
                for (int i = 0; i < valuesB.Length; i++)
                {
                    valuesB2[i] = valuesA[i] + valuesB[i];
                    valuesC2[i] = valuesC[i] + valuesB2[i];
                }

                // plot the bar charts in reverse order (highest first)
                plt.PlotBar(xs, valuesC2, label: "Process C");
                plt.PlotBar(xs, valuesB2, label: "Process B");
                plt.PlotBar(xs, valuesA, label: "Process A");

                // configure ticks for base 16 Y-axis
                plt.Ticks(baseY: 16, prefixY: "0x");
                plt.Axis(-1, 1, 0, 0x1A0000000);

                // further customize the plot
                plt.Ticks(displayTicksX: false, displayTicksY: true);
                plt.Title("Memory Consumption");
                plt.YLabel("Memory (Bytes)");
                plt.Legend();
            }
コード例 #6
0
        public void ReturnPlot(List <DateTime> timestampOfMeasures, List <double> lastMeasures, string name, double minimumValueToBeShownOnPlot, double maximumValueToBeShownOnPlot)
        {
            var           plot       = new Plot(300, 150);
            int           pointCount = 20;
            List <double> dates      = new List <double>();
            List <double> ys         = new List <double>();
            var           start      = timestampOfMeasures[0];

            for (int i = pointCount - lastMeasures.Count; i >= 0; i--)
            {
                ys.Add(0);
                dates.Add(start.AddSeconds(-i * delayProvider.DelayInSeconds - 1).ToOADate());
            }

            List <double> convertedTimestamps = new List <double>();
            List <double> timestampsOfMeasuresConvertedToADate = timestampsConverter.ConvertTimestamps(timestampOfMeasures);

            convertedTimestamps.AddRange(timestampsOfMeasuresConvertedToADate);

            ys.AddRange(lastMeasures);
            dates.AddRange(convertedTimestamps);

            plot.PlotScatter(dates.ToArray(), ys.ToArray());
            plot.Ticks(dateTimeX: true);
            plot.YLabel(name);
            plot.Axis(y1: minimumValueToBeShownOnPlot, y2: maximumValueToBeShownOnPlot);
            plot.SaveFig(@$ "..\Assets\{name}.png");
コード例 #7
0
        void PlotHistogram()
        {
            double[] values   = { 0, 20, 25, 28, 39, 59 };
            var      his      = new ScottPlot.Statistics.Histogram(values, min: 0, max: 70);
            double   barWidth = his.binSize * 1.2;

            plt.PlotBar(his.bins, his.countsFracCurve, barWidth: barWidth, outlineWidth: 0);
            plt.PlotScatter(his.bins, his.countsFracCurve, markerSize: 0, lineWidth: 2, color: Color.Black);
            plt.Axis(null, null, 0, null);
        }
コード例 #8
0
 public void InitSortedPeaksPlot(Plot sortedPeaksPlot)
 {
     sortedPeaksPlot.Frame(false);
     sortedPeaksPlot.Style(Style.Blue2);
     sortedPeaksPlot.Title("Sorted Section Strain Peaks");
     sortedPeaksPlot.YLabel("Aim Strain");
     sortedPeaksPlot.XLabel("Rank");
     sortedPeaksPlot.Axis(x1: -0.5, x2: PEAKS_TO_DISPLAY + 0.5, y1: 0, y2: 100);
     sortedPeaksPlot.Ticks(displayTicksXminor: false);
     sortedPeaksPlot.Grid(xSpacing: 1);
 }
コード例 #9
0
ファイル: Bar.cs プロジェクト: pajek2111/ScottPlot
            public void Render(Plot plt)
            {
                // generate random data to plot
                Random rand       = new Random(0);
                int    pointCount = 10;

                double[] xs = DataGen.Consecutive(pointCount);
                double[] ys = DataGen.RandomNormal(rand, pointCount, 20, 5);

                // let's round the values to simplify display
                ys = Tools.Round(ys, 1);

                // add both bar plot
                plt.PlotBar(xs, ys, showValues: true);

                // customize the plot to make it look nicer
                plt.Axis(y1: 0);
                plt.Grid(enableVertical: false, lineStyle: LineStyle.Dot);
                plt.Axis(y1: 0);
                plt.Legend();
            }
コード例 #10
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            var settings = plt.GetSettings();

            // vertical axis
            plt.YLabel(tbYlabel.Text);
            plt.Ticks(displayTicksYminor: cbYminor.Checked, dateTimeY: cbYdateTime.Checked);
            double y1, y2;

            double.TryParse(tbY1.Text, out y1);
            double.TryParse(tbY2.Text, out y2);
            plt.Axis(y1: y1, y2: y2);

            // horizontal axis
            plt.XLabel(tbXlabel.Text);
            plt.Ticks(displayTicksXminor: cbXminor.Checked, dateTimeX: cbXdateTime.Checked);
            double x1, x2;

            double.TryParse(tbX1.Text, out x1);
            double.TryParse(tbX2.Text, out x2);
            plt.Axis(x1: x1, x2: x2);

            // tick display options
            plt.Ticks(useOffsetNotation: cbTicksOffset.Checked, useMultiplierNotation: cbTicksMult.Checked);

            // image quality
            //plt.AntiAlias(figure: rbQualityHigh.Checked, data: rbQualityHigh.Checked);
            //plt.mouseTracker.lowQualityWhileInteracting = cbQualityLowWhileDragging.Checked;

            // misc
            plt.Grid(enable: cbGrid.Checked);
            plt.Legend(enableLegend: cbLegend.Checked);
            if (cbStyle.Text != "")
            {
                Style newStyle = (Style)Enum.Parse(typeof(Style), cbStyle.Text);
                plt.Style(newStyle);
            }

            Close();
        }
コード例 #11
0
ファイル: AxisLimits.cs プロジェクト: wheregone/ScottPlot
            public void Render(Plot plt)
            {
                int pointCount = 51;

                double[] x   = DataGen.Consecutive(pointCount);
                double[] sin = DataGen.Sin(pointCount);
                double[] cos = DataGen.Cos(pointCount);

                plt.PlotScatter(x, sin);
                plt.PlotScatter(x, cos);

                plt.Axis(-10, 60, -3, 3);
            }
コード例 #12
0
ファイル: Stats.cs プロジェクト: ljtking123/ScottPlot
            public void Render(Plot plt)
            {
                Random rand = new Random(0);

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

                plt.PlotBar(hist.bins, hist.countsFrac);
                plt.PlotScatter(hist.bins, hist.countsFracCurve, markerSize: 0, lineWidth: 2, color: Color.Black);
                plt.Title("Normal Random Data");
                plt.YLabel("Frequency (fraction)");
                plt.XLabel("Value (units)");
                plt.Axis(null, null, 0, null);
            }
コード例 #13
0
        public DifficultyGraph(Input input, BeatmapData beatmap)
        {
            this.beatmap = beatmap;

            var difficultyCalculator = new DifficultyCalculator(input.BeatmapId, input.Gamemode, input.ModNumber);

            difficulty = difficultyCalculator.Calculate();

            double maxDifficulty = (double)beatmap.DifficultyRating > difficulty.StrainPeakTotal.Max() ? (double)beatmap.DifficultyRating : difficulty.StrainPeakTotal.Max();

            var      webClient  = new WebClient();
            Image    background = null;
            Graphics graphic    = null;

            try
            {
                byte[] backgroundBytes  = webClient.DownloadData($"https://assets.ppy.sh/beatmaps/{beatmap.BeatmapSetId}/covers/cover.jpg");
                var    backgroundStream = new MemoryStream(backgroundBytes);
                background = Image.FromStream(backgroundStream);
                graphic    = Graphics.FromImage(background);
            }
            catch (Exception e) { }

            double[] dataX = CreateXRange();

            var plt = new Plot(900, 250);

            plt.Axis(0, beatmap.TotalLength, 0, maxDifficulty + 0.5);
            plt.PlotScatter(dataX, difficulty.StrainPeakTotal, markerSize: 0, label: "Strain", lineWidth: 3, color: Color.DodgerBlue);
            plt.PlotScatter(dataX, difficulty.StrainPeakAim, markerShape: MarkerShape.none, label: "Aim", lineWidth: 1, color: Color.MediumAquamarine, lineStyle: LineStyle.Solid);
            plt.PlotScatter(dataX, difficulty.StrainPeakSpeed, markerShape: MarkerShape.none, label: "Speed", lineWidth: 1, color: Color.Firebrick);
            plt.Title($"{beatmap.Artist} - {beatmap.Title} [{beatmap.Version}]", fontSize: 24);
            plt.Ticks(displayTicksXminor: false, displayTicksYminor: false, fontSize: 16);
            plt.PlotHLine((double)beatmap.DifficultyRating, lineWidth: 1, label: "SR", color: Color.Gold);
            plt.Legend(location: legendLocation.upperLeft, fontSize: 10, fixedLineWidth: true, bold: true);
            plt.Style(figBg: Color.FromArgb(150, 35, 39, 42), dataBg: Color.FromArgb(150, 35, 39, 42), tick: Color.White, title: Color.White, label: Color.White);
            plt.Layout(xLabelHeight: 5, yLabelWidth: -10);

            if (graphic != null && background != null)
            {
                graphic.DrawImage(plt.GetBitmap(), new Point(0, 0));
                Graph = background;
            }
            else
            {
                Graph = plt.GetBitmap();
            }

            //background.Save("output.png", ImageFormat.Png);
        }
コード例 #14
0
            public void Render(Plot plt)
            {
                Random rand = new Random(0);

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

                double barWidth = hist.binSize * 1.2; // slightly over-side to reduce anti-alias rendering artifacts

                plt.PlotBar(hist.bins, hist.countsFrac, barWidth: barWidth, outlineWidth: 0);
                plt.PlotScatter(hist.bins, hist.countsFracCurve, markerSize: 0, lineWidth: 2, color: Color.Black);
                plt.Title("Normal Random Data");
                plt.YLabel("Frequency (fraction)");
                plt.XLabel("Value (units)");
                plt.Axis(null, null, 0, null);
                plt.Grid(lineStyle: LineStyle.Dot);
            }
コード例 #15
0
ファイル: Stats.cs プロジェクト: ljtking123/ScottPlot
            public void Render(Plot plt)
            {
                // create sample data for two datasets
                Random rand = new Random(0);

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

                // display datasets as step plots
                plt.Title("Cumulative Probability Histogram");
                plt.YLabel("Probability (fraction)");
                plt.XLabel("Value (units)");
                plt.PlotStep(hist1.bins, hist1.cumulativeFrac, lineWidth: 1.5, label: "sample A");
                plt.PlotStep(hist2.bins, hist2.cumulativeFrac, lineWidth: 1.5, label: "sample B");
                plt.Legend();
                plt.Axis(null, null, 0, 1);
            }
コード例 #16
0
        /// <inheritdoc />
        public string GenerateAsImage(IEnumerable <QuestionResult> questionResults)
        {
            var path       = Path.Combine(_workFolderPath, GenerateName() + @".png");
            var plot       = new Plot(Width, High);
            var startPoint = (double)MinPointX;

            foreach (var questionResult in questionResults)
            {
                var endPoint = startPoint + questionResult.Quota * (MaxPointX - MinPointX);
                plot.PlotVSpan(startPoint, endPoint, label: SplitTooLongLabel(questionResult.Question));
                startPoint = endPoint;
            }

            plot.XLabel(@"Доля неверных ответов.", fontSize: 4 * FontSize);
            plot.Axis(MinPointX, MaxPointX, MinPointY, MaxPointY);
            plot.Legend(fontSize: FontSize);
            plot.SaveFig(path);

            return(path);
        }
コード例 #17
0
ファイル: Bar.cs プロジェクト: pajek2111/ScottPlot
            public void Render(Plot plt)
            {
                // generate random data to plot
                Random rand       = new Random(0);
                int    pointCount = 5;

                double[] xs     = DataGen.Consecutive(pointCount);
                double[] ys     = DataGen.RandomNormal(rand, pointCount, 20, 5);
                double[] yError = DataGen.RandomNormal(rand, pointCount, 3, 2);

                // make the bar plot
                plt.PlotBar(xs, ys, yError, horizontal: true);

                // customize the plot to make it look nicer
                plt.Axis(x1: 0);
                plt.Grid(enableHorizontal: false, lineStyle: LineStyle.Dot);

                // apply custom axis tick labels
                string[] labels = { "one", "two", "three", "four", "five" };
                plt.YTicks(xs, labels);
            }
コード例 #18
0
ファイル: Bar.cs プロジェクト: pajek2111/ScottPlot
            public void Render(Plot plt)
            {
                // generate random data to plot
                Random rand       = new Random(0);
                int    pointCount = 10;

                double[] xs     = DataGen.Consecutive(pointCount);
                double[] ys     = DataGen.RandomNormal(rand, pointCount, 20, 5);
                double[] yError = DataGen.RandomNormal(rand, pointCount, 5, 2);

                // make the bar plot
                plt.PlotBar(xs, ys, yError);

                // customize the plot to make it look nicer
                plt.Axis(y1: 0);
                plt.Grid(enableVertical: false, lineStyle: LineStyle.Dot);

                // apply custom axis tick labels
                string[] labels = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" };
                plt.XTicks(xs, labels);
            }
コード例 #19
0
ファイル: Bar.cs プロジェクト: zrolfs/ScottPlot
            public void Render(Plot plt)
            {
                int pointCount = 20;

                double[] xs   = new double[pointCount];
                double[] ys   = new double[pointCount];
                double[] yErr = new double[pointCount];
                Random   rand = new Random(0);

                for (int i = 0; i < pointCount; i++)
                {
                    xs[i]   = i;
                    ys[i]   = .5 + rand.NextDouble();
                    yErr[i] = rand.NextDouble() * .3 + .05;
                }

                plt.Title("Bar Plot With Error Bars");
                plt.PlotBar(xs, ys, barWidth: .5, errorY: yErr, errorCapSize: 2);
                plt.Grid(enableVertical: false);
                plt.Axis(null, null, 0, null);
            }
コード例 #20
0
        public Stream GetHistoryPlot(ValorantAccount account)
        {
            if (account.RankInfos.Count == 0)
            {
                return(null);
            }

            var plt = new Plot(600, 400);

            plt.Style(ColorTranslator.FromHtml("#111111"), ColorTranslator.FromHtml("#111111"),
                      ColorTranslator.FromHtml("#22F9F9F9"), ColorTranslator.FromHtml("#FF4654"),
                      ColorTranslator.FromHtml("#FF4654"), ColorTranslator.FromHtml("#F9F9F9"));


            var values = account.RankInfos.OrderBy(r => r.DateTime)
                         .Select(info => (double)info.RankInt * 100 + info.Progress).ToArray();
            var minValue = (double)((int)values.Min() / 100 - 1) * 100;
            var maxValue = (double)((int)values.Max() / 100 + 1) * 100;

            var dates = account.RankInfos.OrderBy(r => r.DateTime).Select(r => r.DateTime.ToOADate()).ToArray();

            plt.PlotScatter(dates, values, ColorTranslator.FromHtml("#FF4654"));
            plt.Legend();

            plt.Axis(y1: minValue, y2: maxValue);
            plt.Title(account.DisplayName);
            plt.XLabel("Date");
            plt.YLabel("Rank");

            var positions = _rank_map.Select((s, i) => (double)i * 100).ToArray();

            plt.YTicks(positions, _rank_map);
            plt.Ticks(dateTimeX: true);

            var stream = new MemoryStream();

            plt.GetBitmap().Save(stream, ImageFormat.Png);
            stream.Seek(0, SeekOrigin.Begin);
            return(stream);
        }
コード例 #21
0
            public void Render(Plot plt)
            {
                // create some sample data to represent test scores
                Random rand = new Random(0);

                double[] scoresA = DataGen.RandomNormal(rand, 35, 72, 7);
                double[] scoresB = DataGen.RandomNormal(rand, 42, 57, 10);
                double[] scoresC = DataGen.RandomNormal(rand, 23, 79, 5);

                // create a unique PopulationSeries for each set of scores
                var seriesA = new Statistics.PopulationSeries(new Statistics.Population[] { new Statistics.Population(scoresA) }, "Class A");
                var seriesB = new Statistics.PopulationSeries(new Statistics.Population[] { new Statistics.Population(scoresB) }, "Class B");
                var seriesC = new Statistics.PopulationSeries(new Statistics.Population[] { new Statistics.Population(scoresC) }, "Class C");

                // create a MultiSeries from all the individual series
                var multiSeries = new Statistics.PopulationMultiSeries(new Statistics.PopulationSeries[] { seriesA, seriesB, seriesC });

                // save the plottable and modify its properties to customize display style
                var popPlot = plt.PlotPopulations(multiSeries);

                popPlot.displayDistributionCurve   = true;
                popPlot.distributionCurveLineStyle = LineStyle.Dash;
                popPlot.scatterOutlineColor        = System.Drawing.Color.Transparent;
                popPlot.displayItems = Plottable.PopulationPlot.DisplayItems.ScatterAndBox;
                popPlot.boxStyle     = Plottable.PopulationPlot.BoxStyle.BarMeanStDev;
                plt.Axis(y1: 0);

                // colors are managed at the population series level:
                foreach (var popSeries in popPlot.popMultiSeries.multiSeries)
                {
                    popSeries.color = Tools.GetRandomColor(rand);
                }

                // improve the style of the plot
                plt.Title($"Test Scores by Class");
                plt.YLabel("Score");
                plt.Legend(location: Alignment.LowerLeft);
                plt.Ticks(displayTicksX: false);
                plt.Grid(lineStyle: LineStyle.Dot, enableVertical: false);
            }
コード例 #22
0
        public void UpdateAimStrainMeter(Plot aimStrainMeter, List <double> denseAimStrainTimes, List <double> denseAimStrainValues, List <double> aimStrainPeakTimes, List <double> aimStrainPeaks, int gameTime)
        {
            double strain = Math.Round(CalculateCurrentStrain(denseAimStrainTimes, denseAimStrainValues, gameTime));

            // Show aim strain peak
            double sectionStart         = (gameTime / 400) * 400;
            var    indicesInsideSection = Enumerable.Range(0, denseAimStrainTimes.Count - 1)
                                          .Where(i => denseAimStrainTimes[i] >= sectionStart)
                                          .Where(i => denseAimStrainTimes[i] <= gameTime);
            double currentStrainPeak = 0;

            foreach (int i in indicesInsideSection)
            {
                currentStrainPeak = Math.Max(denseAimStrainValues[i], currentStrainPeak);
            }
            aimStrainMeter.PlotBar(
                new double[] { 0 },
                new double[] { currentStrainPeak },
                fillColor: Color.FromArgb(40, 189, 147, 249),
                outlineWidth: 0
                );
            aimStrainMeter.PlotText(
                Math.Round(currentStrainPeak).ToString(),
                0, currentStrainPeak + 20,
                color: Color.FromArgb(230, 230, 230),
                alignment: TextAlignment.middleCenter,
                fontSize: 15
                );

            aimStrainMeter.PlotBar(
                new double[] { 0 },
                new double[] { strain },
                fillColor: Color.FromArgb(255, 85, 85),
                outlineWidth: 0
                );
            aimStrainMeter.Ticks(displayTicksX: false);
            aimStrainMeter.Grid(enableVertical: false);
            aimStrainMeter.Axis(y1: 0, y2: denseAimStrainValues.Max() + 50);
            aimStrainMeter.Frame(false);
        }
コード例 #23
0
        /// <inheritdoc />
        public string GenerateAsImage(IEnumerable <UserResult> userResults)
        {
            var path = Path.Combine(_workFolderPath, GenerateName() + @".png");
            var plot = new Plot(Width, High);

            if (userResults.Any())
            {
                var minimum = userResults.Min(result => result.Result.Keys.Min());
                var maximum = userResults.Max(result => result.Result.Keys.Max());
                foreach (var result in userResults)
                {
                    plot.PlotScatter(
                        ConvertDateToDouble(result.Result.Keys, minimum, maximum).ToArray(),
                        result.Result.Values.Select(item => (double)item).ToArray(),
                        label: result.User,
                        markerSize: 10);

                    SetLabels(
                        plot,
                        result.Result.Keys,
                        result.Result.Values.Select(item => (double)item), minimum,
                        maximum);
                }

                plot.XLabel(
                    (maximum - minimum).TotalHours <= 24
                        ? @"Время прохождения теста."
                        : @"Дата прохождения теста.",
                    fontSize: 4 * FontSize);
            }

            plot.YLabel(@"Доля верных ответов.", fontSize: 4 * FontSize);
            plot.Axis(MinPointX, MaxPointX, MinPointY, MaxPointY);
            plot.Legend(fontSize: 2 * FontSize);
            plot.SaveFig(path);

            return(path);
        }
コード例 #24
0
ファイル: Util.cs プロジェクト: Hyosya/ImageProccessing100
        public static Mat MakeHistogram(Mat mat)
        {
            double[] array;
            unsafe
            {
                var span = new ReadOnlySpan <byte>(mat.Data.ToPointer(), (int)mat.Total() * mat.Channels());
                array = new double[span.Length];
                for (int i = 0; i < span.Length; i++)
                {
                    array[i] = span[i];
                }
            }

            var plt  = new Plot(640, 480);
            var hist = new ScottPlot.Statistics.Histogram(array, min: 0, max: 255, binSize: 1);

            plt.PlotBar(hist.bins, hist.counts, barWidth: hist.binSize, outlineWidth: 0);
            plt.Axis(null, null, 0, null);
            plt.Grid(lineStyle: LineStyle.Dot);
            var bitmap = plt.GetBitmap();

            return(bitmap.ToMat());
        }
コード例 #25
0
ファイル: Bar.cs プロジェクト: pajek2111/ScottPlot
            public void Render(Plot plt)
            {
                // create some sample data
                double[] xs      = { 1, 2, 3, 4, 5, 6, 7 };
                double[] valuesA = { 1, 2, 3, 2, 1, 2, 1 };
                double[] valuesB = { 3, 3, 2, 1, 3, 2, 1 };

                // to simulate stacking B on A, shift B up by A
                double[] valuesB2 = new double[valuesB.Length];
                for (int i = 0; i < valuesB.Length; i++)
                {
                    valuesB2[i] = valuesA[i] + valuesB[i];
                }

                // plot the bar charts in reverse order (highest first)
                plt.PlotBar(xs, valuesB2, label: "Series B");
                plt.PlotBar(xs, valuesA, label: "Series A");

                // improve the styling
                plt.Legend(location: legendLocation.upperRight);
                plt.Axis(y1: 0, y2: 7);
                plt.Title("Stacked Bar Charts");
            }
コード例 #26
0
        private void PopualteGuiFromPlot()
        {
            // vertical axis
            tbYlabel.Text       = plt.GetSettings().yLabel.text;
            tbY2.Text           = Math.Round(plt.Axis()[3], 4).ToString();
            tbY1.Text           = Math.Round(plt.Axis()[2], 4).ToString();
            cbYminor.Checked    = plt.GetSettings().ticks.displayYminor;
            cbYdateTime.Checked = plt.GetSettings().ticks.y.dateFormat;

            // horizontal axis
            tbXlabel.Text       = plt.GetSettings().xLabel.text;
            tbX2.Text           = Math.Round(plt.Axis()[1], 4).ToString();
            tbX1.Text           = Math.Round(plt.Axis()[0], 4).ToString();
            cbXminor.Checked    = plt.GetSettings().ticks.displayXminor;
            cbXdateTime.Checked = plt.GetSettings().ticks.x.dateFormat;

            // tick display options
            cbTicksOffset.Checked = plt.GetSettings().ticks.useOffsetNotation;
            cbTicksMult.Checked   = plt.GetSettings().ticks.useMultiplierNotation;
            cbGrid.Checked        = plt.GetSettings().grid.enableHorizontal;

            // legend
            cbLegend.Checked = (plt.GetSettings().legend.location == legendLocation.none) ? false : true;

            // image quality
            rbQualityLow.Checked  = !plt.GetSettings().misc.antiAliasData;
            rbQualityHigh.Checked = plt.GetSettings().misc.antiAliasData;
            //cbQualityLowWhileDragging.Checked = plt.mouseTracker.lowQualityWhileInteracting;

            // list of plottables
            lbPlotObjects.Items.Clear();
            foreach (var plotObject in plt.GetPlottables())
            {
                lbPlotObjects.Items.Add(plotObject);
            }

            // list of color styles
            cbStyle.Items.AddRange(Enum.GetNames(typeof(Style)));
        }
コード例 #27
0
 public void Render(Plot plt)
 {
     GenericPlots.SinAndCos(plt);
     plt.Axis(-10, 60, -3, 3);
 }
コード例 #28
0
ファイル: Legend.cs プロジェクト: wheregone/ScottPlot
            public void Render(Plot plt)
            {
                Random rand = new Random(0);

                plt.PlotErrorBars(
                    xs: DataGen.Random(rand, 10, 10),
                    ys: DataGen.Random(rand, 10, 10),
                    xPositiveError: DataGen.Random(rand, 10),
                    xNegativeError: DataGen.Random(rand, 10),
                    yPositiveError: DataGen.Random(rand, 10),
                    yNegativeError: DataGen.Random(rand, 10),
                    label: "error bars"
                    );

                var func = new Func <double, double?>((x) => Math.Sin(x) * Math.Sin(10 * x) + 3);

                plt.PlotFunction(func, label: "function", lineWidth: 2);

                var func2 = new Func <double, double?>((x) => Math.Sin(x) * Math.Sin(10 * x) + 5);

                plt.PlotFunction(func2, label: null); // null labels will not appear in legend

                plt.PlotHLine(7.75, label: "horizontal line", lineStyle: LineStyle.Dot);
                plt.PlotVLine(7.75, label: "vertical line", lineStyle: LineStyle.Dash);

                plt.PlotHSpan(1.5, 2.5, label: "horizontal span");
                plt.PlotVSpan(1.5, 2.5, label: "vertical span");

                plt.PlotOHLC(new OHLC[] {
                    new OHLC(5, 6, 4, 5.5, 1),
                    new OHLC(6, 7.5, 3.5, 4.75, 1.5),
                    new OHLC(5.5, 6, 3, 4.5, 2)
                });

                plt.PlotCandlestick(new OHLC[] {
                    new OHLC(5, 6, 4, 5.5, 3),
                    new OHLC(6, 7.5, 3.5, 4.75, 3.5),
                    new OHLC(5.5, 6, 3, 4.5, 4)
                });

                plt.PlotScatter(
                    xs: new double[] { 5, 5.5, 6, 7, 7, 6 },
                    ys: new double[] { 7, 8, 7, 9, 7, 8 },
                    lineStyle: LineStyle.Dash,
                    lineWidth: 2,
                    markerShape: MarkerShape.openCircle,
                    markerSize: 10,
                    label: "Scatter Plot"
                    );

                plt.PlotSignal(
                    ys: DataGen.RandomNormal(rand, 10),
                    sampleRate: 5,
                    xOffset: 3,
                    yOffset: 8,
                    label: "Signal Plot"
                    );

                plt.PlotText("ScottPlot", 6, 6, rotation: 25, fontSize: 14, bold: true);

                plt.PlotPoint(1, 9, label: "point");
                plt.PlotArrow(8, 8, 8.5, 8.5, label: "arrow");

                plt.Axis(0, 13, -1, 11);
                plt.Legend();
                plt.Grid(false);
            }
コード例 #29
0
        public void PlotSortedPeaks(Plot sortedPeaksPlot, List <double> aimStrainPeakTimes, List <double> aimStrainPeaks, double gameTime)
        {
            // Mark 7 (50%), 22 (90%), and 28 (95%)
            sortedPeaksPlot.PlotVLine(7.5, color: Color.FromArgb(255, 121, 198), lineStyle: LineStyle.Dot);
            sortedPeaksPlot.PlotVLine(22.5, color: Color.FromArgb(255, 121, 198), lineStyle: LineStyle.Dot);
            sortedPeaksPlot.PlotVLine(28.5, color: Color.FromArgb(255, 121, 198), lineStyle: LineStyle.Dot);

            // get all aim strains before gameTime, limit view to only the first PEAKS_TO_DISPLAY peaks
            var sortedPeaks = Enumerable.Zip(aimStrainPeakTimes, aimStrainPeaks, (time, value) => (time, value))
                              .Where(peak => peak.time < gameTime)
                              .OrderBy(peak => peak.value)
                              .Reverse();
            var allRanks    = Enumerable.Range(0, sortedPeaks.Count()).Select(x => (double)x).ToArray();
            var rankedPeaks = sortedPeaks.Zip(allRanks, (p, rank) => (rank, p.time, p.value))
                              .Where(p => p.rank <= PEAKS_TO_DISPLAY);
            var limitedRanks = rankedPeaks.Select(p => p.rank).ToArray();

            // Plot old peaks
            var oldPeaks = rankedPeaks.Where(p => gameTime > p.time + OLD_THRESHOLD);

            if (oldPeaks.Count() > 0)
            {
                sortedPeaksPlot.PlotBar(
                    oldPeaks.Select(p => p.rank).ToArray(),
                    oldPeaks.Select(p => Math.Round(p.value)).ToArray(),
                    barWidth: 0.95,
                    fillColor: Color.FromArgb(70, 189, 147, 249),
                    outlineWidth: 0
                    );
            }

            // Plot recent peaks
            var newPeaks = rankedPeaks.Where(p => gameTime <= p.time + OLD_THRESHOLD);

            foreach ((double rank, double time, double value) in newPeaks)
            {
                var progress     = (gameTime - time) / OLD_THRESHOLD;
                int transparency = (int)(255 - progress * (255 - 70));
                sortedPeaksPlot.PlotBar(
                    new double[] { rank },
                    new double[] { Math.Round(value) },
                    barWidth: 0.95,
                    fillColor: Color.FromArgb(transparency, 189, 147, 249),
                    outlineWidth: 0
                    );
            }
            LastSortedPeaksPlotContainedNewPeaks = newPeaks.Count() > 0;

            // Plot weighted peaks
            var weightedPeaks = rankedPeaks
                                .Select(p => p.value * Math.Pow(0.90, p.rank))
                                .Select(x => Math.Round(x))
                                .ToArray();

            if (weightedPeaks.Length > 0)
            {
                sortedPeaksPlot.PlotBar(
                    limitedRanks,
                    weightedPeaks,
                    barWidth: 0.95,
                    fillColor: Color.FromArgb(70, 189, 147, 249),
                    outlineWidth: 0
                    );
            }
            //sortedPeaksPlot.AxisAuto(xExpandOnly: true, yExpandOnly: true);
            sortedPeaksPlot.Axis(x1: -0.5, x2: PEAKS_TO_DISPLAY + 0.5, y1: 0, y2: aimStrainPeaks.Max());
        }