Ejemplo n.º 1
0
        public void ExecuteRecipe(Plot plt)
        {
            // plot sample data
            plt.AddSignal(DataGen.Sin(51));
            plt.AddSignal(DataGen.Cos(51));

            // add axis lines
            plt.AddHorizontalLine(.85);
            plt.AddVerticalLine(23);

            // customize axis lines with optional arguments
            plt.AddVerticalLine(x: 33, color: Color.Magenta, width: 3, style: LineStyle.Dot);
        }
Ejemplo n.º 2
0
        public void ExecuteRecipe(Plot plt)
        {
            var plot1 = plt.AddScatter(new double[] { 2.5 }, new double[] { 5 }, label: "John Doe et al.");

            plot1.XError = new double[] { 0.2 };

            var plot2 = plt.AddScatter(new double[] { 2.7 }, new double[] { 4 }, label: "Jane Doe et al.");

            plot2.XError = new double[] { 0.3 };

            var plot3 = plt.AddScatter(new double[] { 2.3 }, new double[] { 3 }, label: "Jim Doe et al.");

            plot3.XError = new double[] { 0.6 };

            var plot4 = plt.AddScatter(new double[] { 2.8 }, new double[] { 2 }, label: "Joel Doe et al.");

            plot4.XError = new double[] { 0.3 };

            var plot5 = plt.AddScatter(new double[] { 2.5 }, new double[] { 1 }, label: "Jacqueline Doe et al.");

            plot5.XError = new double[] { 0.2 };

            plt.AddVerticalLine(2.6, style: LineStyle.Dash);

            plt.SetAxisLimits(0, 5, 0, 6);
            plt.Legend();
        }
Ejemplo n.º 3
0
        public void ExecuteRecipe(Plot plt)
        {
            double CustomSnapFunction(double value)
            {
                // multiple of 3 between 0 and 50
                if (value < 0)
                {
                    return(0);
                }
                else if (value > 50)
                {
                    return(50);
                }
                else
                {
                    return((int)Math.Round(value / 3) * 3);
                }
            }

            // different snap sytems can be created and customized
            var SnapDisabled = new ScottPlot.SnapLogic.NoSnap1D();
            var SnapCustom   = new SnapLogic.Custom1D(CustomSnapFunction);

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

            var vLine = plt.AddVerticalLine(30);

            vLine.DragEnabled = true;
            vLine.DragSnap    = new ScottPlot.SnapLogic.Independent2D(SnapCustom, SnapDisabled);
        }
Ejemplo n.º 4
0
        public void ExecuteRecipe(Plot plt)
        {
            plt.AddFunction(x => Math.Pow(x, 2), lineStyle: LineStyle.Dash);
            plt.AddFunction(x => Math.Sqrt(x), lineStyle: LineStyle.Dash);

            // mark a coordinate from the lower left
            var point1 = plt.AddPoint(1, 1, size: 10, shape: MarkerShape.openCircle);
            var hLine1 = plt.AddHorizontalLine(1, width: 2);

            hLine1.Max   = 1;
            hLine1.Color = point1.Color;
            var vLine1 = plt.AddVerticalLine(1, width: 2);

            vLine1.Max   = 1;
            vLine1.Color = point1.Color;

            // use finate upper and lower limits draw a cross on a point
            var point2 = plt.AddPoint(4, 2, size: 10, shape: MarkerShape.openCircle);
            var vLine2 = plt.AddVerticalLine(4, width: 2);

            vLine2.Min   = 1.5;
            vLine2.Max   = 2.5;
            vLine2.Color = point2.Color;
            var hLine2 = plt.AddHorizontalLine(2, width: 2);

            hLine2.Min   = 3.5;
            hLine2.Max   = 4.5;
            hLine2.Color = point2.Color;

            // mark a coordinate from the top right
            var point3 = plt.AddPoint(2, 4, size: 10, shape: MarkerShape.openCircle);
            var hLine3 = plt.AddHorizontalLine(4, width: 2);

            hLine3.Min   = 2;
            hLine3.Color = point3.Color;
            var vLine3 = plt.AddVerticalLine(2, width: 2);

            vLine3.Min   = 4;
            vLine3.Color = point3.Color;

            plt.SetAxisLimits(0, 5, 0, 5);
        }
Ejemplo n.º 5
0
        public void ExecuteRecipe(Plot plt)
        {
            // generate sample heights are based on https://ourworldindata.org/human-height
            Random rand = new(0);

            double[] values = ScottPlot.DataGen.RandomNormal(rand, pointCount: 1234, mean: 178.4, stdDev: 7.6);

            // create a histogram
            (double[] counts, double[] binEdges) = ScottPlot.Statistics.Common.Histogram(values, min: 140, max: 220, binSize: 1);
            double[] leftEdges = binEdges.Take(binEdges.Length - 1).ToArray();

            // display histogram probabability as a bar plot
            var bar = plt.AddBar(values: counts, positions: leftEdges);

            bar.FillColor       = ColorTranslator.FromHtml("#9bc3eb");
            bar.BorderLineWidth = 0;

            // display histogram distribution curve as a line plot on a secondary Y axis
            double[] smoothEdges     = ScottPlot.DataGen.Range(start: binEdges.First(), stop: binEdges.Last(), step: 0.1, includeStop: true);
            double[] smoothDensities = ScottPlot.Statistics.Common.ProbabilityDensity(values, smoothEdges, percent: true);
            var      probPlot        = plt.AddScatterLines(
                xs: smoothEdges,
                ys: smoothDensities,
                lineWidth: 2,
                label: "probability");

            probPlot.YAxisIndex = 1;
            plt.YAxis2.Ticks(true);

            // display vertical lines at points of interest
            var stats = new ScottPlot.Statistics.BasicStats(values);

            plt.AddVerticalLine(stats.Mean, Color.Black, 2, LineStyle.Solid, "mean");

            plt.AddVerticalLine(stats.Mean - stats.StDev, Color.Black, 2, LineStyle.Dash, "1 SD");
            plt.AddVerticalLine(stats.Mean + stats.StDev, Color.Black, 2, LineStyle.Dash);

            plt.AddVerticalLine(stats.Mean - stats.StDev * 2, Color.Black, 2, LineStyle.Dot, "2 SD");
            plt.AddVerticalLine(stats.Mean + stats.StDev * 2, Color.Black, 2, LineStyle.Dot);

            plt.AddVerticalLine(stats.Min, Color.Gray, 1, LineStyle.Dash, "min/max");
            plt.AddVerticalLine(stats.Max, Color.Gray, 1, LineStyle.Dash);

            plt.Legend(location: Alignment.UpperRight);

            // customize the plot style
            plt.Title("Adult Male Height");
            plt.YAxis.Label("Count (#)");
            plt.YAxis2.Label("Probability (%)");
            plt.XAxis.Label("Height (cm)");
            plt.SetAxisLimits(yMin: 0);
            plt.SetAxisLimits(yMin: 0, yAxisIndex: 1);
        }
Ejemplo n.º 6
0
        public void ExecuteRecipe(Plot plt)
        {
            plt.AddSignal(DataGen.Sin(51, mult: 5));
            plt.AddSignal(DataGen.Cos(51, mult: 5));
            double[] snapPositions = DataGen.Consecutive(11, 5);

            // different snap sytems can be created and customized
            var SnapDisabled      = new ScottPlot.SnapLogic.NoSnap1D();
            var SnapNearestInt    = new ScottPlot.SnapLogic.Integer1D();
            var SnapNearestInList = new ScottPlot.SnapLogic.Nearest1D(snapPositions);

            var hLine = plt.AddHorizontalLine(2);

            hLine.DragEnabled = true;
            hLine.DragSnap    = new ScottPlot.SnapLogic.Independent2D(x: SnapDisabled, y: SnapNearestInt);

            var vLine = plt.AddVerticalLine(30);

            vLine.DragEnabled = true;
            vLine.DragSnap    = new ScottPlot.SnapLogic.Independent2D(x: SnapNearestInList, y: SnapDisabled);
        }
Ejemplo n.º 7
0
        public void ExecuteRecipe(Plot plt)
        {
            // plot sample data
            plt.AddSignal(DataGen.Sin(51));
            plt.AddSignal(DataGen.Cos(51));

            // add axis lines and configure their drag settings
            var hLine = plt.AddHorizontalLine(.85);

            hLine.DragEnabled  = true;
            hLine.DragLimitMin = -1;
            hLine.DragLimitMax = 1;

            var vLine = plt.AddVerticalLine(23);

            vLine.DragEnabled  = true;
            vLine.DragLimitMin = 0;
            vLine.DragLimitMax = 50;

            // you can access the position of an axis line at any time
            string message = $"Vertical line is at X={vLine.X}";
        }
Ejemplo n.º 8
0
        public void ExecuteRecipe(Plot plt)
        {
            plt.AddSignal(DataGen.Sin(51));
            plt.AddSignal(DataGen.Cos(51));

            var hline = plt.AddHorizontalLine(.85);

            hline.LineWidth               = 2;
            hline.PositionLabel           = true;
            hline.PositionLabelBackground = hline.Color;
            hline.DragEnabled             = true;

            var vline = plt.AddVerticalLine(23);

            vline.LineWidth               = 2;
            vline.PositionLabel           = true;
            vline.PositionLabelBackground = vline.Color;
            vline.DragEnabled             = true;

            Func <double, string> xFormatter = x => $"X={x:F2}";

            vline.PositionFormatter = xFormatter;
        }