Example #1
0
            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);

                Bitmap image = DataGen.SampleImage();

                plt.PlotBitmap(image, 5, 0.8);
                plt.AddPoint(5, 0.8, color: Color.Green);

                plt.PlotBitmap(image, 20, 0.3);
                plt.AddPoint(20, 0.3, color: Color.Black, markerSize: 15);

                plt.PlotBitmap(image, 30, 0, alignment: Alignment.MiddleCenter);
                plt.AddPoint(30, 0, color: Color.Black, markerSize: 15);

                plt.PlotBitmap(image, 30, -0.3, alignment: Alignment.UpperLeft);
                plt.AddPoint(30, -0.3, color: Color.Black, markerSize: 15);

                plt.PlotBitmap(image, 5, -.5, rotation: -30);
                plt.AddPoint(5, -.5, color: Color.Blue, markerSize: 15);

                plt.PlotBitmap(image, 15, -.6, frameSize: 3, frameColor: Color.Magenta);
            }
Example #2
0
        public void ExecuteRecipe(Plot plt)
        {
            // display some sample data
            plt.AddSignal(DataGen.Sin(51));
            plt.AddSignal(DataGen.Cos(51));

            // display an image with 3 different alignments
            Bitmap monaLisa = DataGen.SampleImage();
            var    ip1      = new ScottPlot.Plottable.Image()
            {
                Bitmap = monaLisa, X = 10
            };
            var ip2 = new ScottPlot.Plottable.Image()
            {
                Bitmap = monaLisa, X = 25, Alignment = Alignment.MiddleCenter
            };
            var ip3 = new ScottPlot.Plottable.Image()
            {
                Bitmap = monaLisa, X = 40, Alignment = Alignment.LowerRight
            };

            plt.Add(ip1);
            plt.Add(ip2);
            plt.Add(ip3);

            plt.AddPoint(ip1.X, ip1.Y, Color.Magenta, size: 20);
            plt.AddPoint(ip2.X, ip2.Y, Color.Magenta, size: 20);
            plt.AddPoint(ip3.X, ip3.Y, Color.Magenta, size: 20);
        }
Example #3
0
            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.AddPoint(25, 0.8, color: Color.Green);
                plt.PlotText(" important point", 25, 0.8, color: Color.Green);

                plt.AddPoint(30, 0.3, color: Color.Black, markerSize: 15);
                plt.PlotText(" default alignment", 30, 0.3, fontSize: 16, bold: true, color: Color.Magenta);

                plt.AddPoint(30, 0, color: Color.Black, markerSize: 15);
                plt.PlotText("middle center", 30, 0, fontSize: 16, bold: true, color: Color.Magenta, alignment: Alignment.MiddleCenter);

                plt.AddPoint(30, -0.3, color: Color.Black, markerSize: 15);
                plt.PlotText("upper left", 30, -0.3, fontSize: 16, bold: true, color: Color.Magenta, alignment: Alignment.UpperLeft);

                plt.AddPoint(5, -.5, color: Color.Blue, markerSize: 15);
                plt.PlotText(" Rotated Text", 5, -.5, fontSize: 16, color: Color.Blue, bold: true, rotation: -30);

                plt.PlotText("Framed Text", 15, -.6, fontSize: 16, color: Color.White, bold: true, frame: true, frameColor: Color.DarkRed);
            }
Example #4
0
        public void ExecuteRecipe(Plot plt)
        {
            ScottPlot.Alignment[] alignments = (ScottPlot.Alignment[])Enum.GetValues(typeof(ScottPlot.Alignment));

            for (int i = 0; i < alignments.Length; i++)
            {
                double frac = (double)i / alignments.Length;
                double x    = Math.Sin(frac * Math.PI * 2);
                double y    = Math.Cos(frac * Math.PI * 2);

                var txt = plt.AddText(alignments[i].ToString(), x, y);
                txt.Alignment       = alignments[i];
                txt.Font.Color      = Color.Black;;
                txt.BackgroundColor = Color.LightSteelBlue;
                txt.BackgroundFill  = true;
                txt.Rotation        = 5;
                txt.BorderSize      = 2;
                txt.BorderColor     = Color.Navy;
                txt.DragEnabled     = true;

                plt.AddPoint(x, y, Color.Red, 10);
            }

            plt.Margins(.5, .2);
        }
Example #5
0
        public void ExecuteRecipe(Plot plt)
        {
            plt.AddSignal(DataGen.Sin(51));
            plt.AddSignal(DataGen.Cos(51));

            Bitmap monaLisa = DataGen.SampleImage();

            plt.AddImage(monaLisa, 10, .5, rotation: 30);
            plt.AddPoint(10, .5, color: Color.Magenta, size: 20);

            plt.AddImage(monaLisa, 25, 0, rotation: -30);
            plt.AddPoint(25, 0, color: Color.Magenta, size: 20);

            plt.AddImage(monaLisa, 45, 0, rotation: 30, anchor: Alignment.MiddleCenter);
            plt.AddPoint(45, 0, color: Color.Magenta, size: 20);
        }
Example #6
0
        public void ExecuteRecipe(Plot plt)
        {
            plt.AddSignal(DataGen.Sin(51));
            plt.AddSignal(DataGen.Cos(51));

            Bitmap monaLisa = DataGen.SampleImage();

            plt.AddImage(monaLisa, 10, 0);
            plt.AddPoint(10, 0, Color.Magenta, size: 20);

            plt.AddImage(monaLisa, 25, 0, anchor: Alignment.MiddleCenter);
            plt.AddPoint(25, 0, Color.Magenta, size: 20);

            plt.AddImage(monaLisa, 40, 0, anchor: Alignment.LowerRight);
            plt.AddPoint(40, 0, Color.Magenta, size: 20);
        }
Example #7
0
            public void Render(Plot plt)
            {
                int pointCount = 51;

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

                // draw something to make the plot interesting
                plt.PlotScatter(x, sin);
                plt.PlotScatter(x, cos);

                // add a few points
                plt.AddPoint(25, 0.8);
                plt.AddPoint(30, 0.3, color: Color.Magenta, markerSize: 15);
            }
Example #8
0
        public void ExecuteRecipe(Plot plt)
        {
            // display some sample data
            plt.AddSignal(DataGen.Sin(51));
            plt.AddSignal(DataGen.Cos(51));

            Bitmap monaLisa = DataGen.SampleImage();

            var img = plt.AddImage(monaLisa, 10, .5);

            img.HeightInAxisUnits = 1;
            img.WidthInAxisUnits  = 30;

            // 4 corners of the image remain fixed in coordinate space
            plt.AddPoint(10, .5, color: Color.Magenta, size: 20);
            plt.AddPoint(40, .5, color: Color.Green, size: 20);
            plt.AddPoint(10, -.5, color: Color.Green, size: 20);
            plt.AddPoint(40, -.5, color: Color.Green, size: 20);
        }
        void TakeWidthSurafce()
        {
            double w, have;

            surface.FindSurfaceWidth(out w, out have);
            double logsteps = Math.Log10(surface.nAddedParticles);

            plotCurveW_t.AddPoint(logsteps, Math.Log10(w));
            plotCurvehAve_t.AddPoint(logsteps, Math.Log10(have));
        }
Example #10
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);
        }
Example #11
0
        public void ExecuteRecipe(Plot plt)
        {
            int pointCount = 51;

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

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

            plt.AddPoint(25, 0.8, color: Color.Green);
            var t1 = plt.AddText(" Important Point (1)", 25, 0.8, 16, Color.Green);

            plt.AddPoint(30, 0.3, color: Color.Black, size: 15);
            var t2 = plt.AddText(" Default alignment (2)", 30, 0.3, 16);

            plt.AddPoint(30, 0, color: Color.Black, size: 15);
            var t3 = plt.AddText("Middle center (3)", 30, 0, 16);

            t3.Alignment = Alignment.MiddleCenter;

            plt.AddPoint(30, -0.3, color: Color.Black, size: 15);
            var t4 = plt.AddText("Upper left (4)", 30, -0.3, 16);

            t4.Alignment = Alignment.UpperLeft;

            plt.AddPoint(5, -.5, color: Color.Blue, size: 15);
            var t5 = plt.AddText(" Rotated Text (5)", 5, -.5, 16);

            t5.Rotation = -30;

            var t6 = plt.AddText(" Filled Background (6)", 15, -.6, 16);

            t6.Color           = Color.Red;
            t6.FontBold        = true;
            t6.BackgroundFill  = true;
            t6.BackgroundColor = Color.LightBlue;
        }
Example #12
0
        private static Plot CreateClusterizingPlot(Dictionary <PointF, List <PointF> > data)
        {
            Plot plot = new Plot();

            foreach (KeyValuePair <PointF, List <PointF> > cluster in data)
            {
                Color color = plot.GetNextColor();

                plot.AddPoint(cluster.Key.X, cluster.Key.Y, color, 25);
                plot.AddScatterPoints(cluster.Value, color);
            }

            return(plot);
        }
Example #13
0
        public void ExecuteRecipe(Plot plt)
        {
            // display some sample data
            plt.AddSignal(DataGen.Sin(51));
            plt.AddSignal(DataGen.Cos(51));

            // place a rotated image on the plot
            Bitmap monaLisa = DataGen.SampleImage();
            var    ip1      = new ScottPlot.Plottable.Image()
            {
                Bitmap = monaLisa, X = 10, Y = .5, Rotation = 30
            };

            plt.Add(ip1);
            plt.AddPoint(ip1.X, ip1.Y, color: Color.Magenta, size: 20);
        }
Example #14
0
        public void ExecuteRecipe(Plot plt)
        {
            var cmap = ScottPlot.Drawing.Colormap.Viridis;

            plt.AddColorbar(cmap);

            Random rand = new(0);

            for (int i = 0; i < 1000; i++)
            {
                double x               = ScottPlot.DataGen.RandomNormalValue(rand, mean: 0, stdDev: .5);
                double y               = ScottPlot.DataGen.RandomNormalValue(rand, mean: 0, stdDev: .5);
                double colorFraction   = Math.Sqrt(x * x + y * y);
                System.Drawing.Color c = ScottPlot.Drawing.Colormap.Viridis.GetColor(colorFraction);
                plt.AddPoint(x, y, c);
            }
        }
Example #15
0
            public void Render(Plot plt)
            {
                int    pointCount = 100;
                Random rand       = new Random(0);

                double[] xs = DataGen.Consecutive(pointCount, 0.1);
                double[] ys = DataGen.NoisySin(rand, pointCount);

                // optional arguments customize highlighted point color, shape, and size
                var sph = plt.PlotScatterHighlight(xs, ys);

                // you can clear previously-highlighted points
                sph.HighlightPoint(4);
                sph.HighlightClear();

                // highlight the point nearest an X (or Y) position
                plt.PlotVLine(8.123, lineStyle: LineStyle.Dash);
                sph.HighlightPointNearestX(8.123);

                // or highlight the point nearest another point in 2D space
                plt.AddPoint(4.43, 1.48);
                sph.HighlightPointNearest(4.43, 1.48);
            }
Example #16
0
        public void ExecuteRecipe(Plot plt)
        {
            // add sample data
            Color clearGray = Color.FromArgb(20, Color.Black);

            plt.AddSignal(DataGen.Sin(51), color: clearGray);
            plt.AddSignal(DataGen.Cos(51), color: clearGray);

            // add a few points around the plot
            plt.AddPoint(5, .5);
            plt.AddPoint(31, 1);
            plt.AddPoint(42, -.25);

            // add points using optional arguments for customization
            plt.AddPoint(7, .15, Color.Magenta, size: 20, shape: MarkerShape.openDiamond);
            plt.AddPoint(23, -1, Color.Navy, size: 20, shape: MarkerShape.filledSquare);
            plt.AddPoint(37, .3, Color.Red, size: 20, shape: MarkerShape.triUp);
        }
Example #17
0
            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.AddPoint(1, 9, label: "point");
                plt.PlotArrow(8, 8, 8.5, 8.5, label: "arrow");

                plt.SetAxisLimits(0, 13, -1, 11);
                plt.Legend();
                plt.Grid(false);
            }
Example #18
0
        public static void Main(string[] args)
        {
            Plot    generatedDataPlot = new Plot();
            Spawner spawner           = new Spawner(STD_DEV);

            List <PointF> allPoints = new List <PointF>();

            for (int i = 0; i < CLUSTER_COUNT; ++i)
            {
                spawner.ResetCenter(MIN_CENTER_DISTANCE, MAX_CENTER_DISTANCE);

                PointF[] points = spawner.Spawn(POINT_COUNT);
                allPoints.AddRange(points);

                Color color = generatedDataPlot.GetNextColor();

                generatedDataPlot.AddScatterPoints(points, color, label: $"Points {i + 1}");
                generatedDataPlot.AddPoint(spawner.Center.X, spawner.Center.Y, color, 25);
            }

            generatedDataPlot.Legend();

            PlotForm generatedDataPlotForm = new PlotForm(generatedDataPlot, "source_data");

            generatedDataPlotForm.ShowDialog();

            Plot grayDataPlot = new Plot();

            grayDataPlot.AddScatterPoints(allPoints.ToArray(), label: "Gray points");
            grayDataPlot.Legend();

            PlotForm grayDataPlotForm = new PlotForm(grayDataPlot, "gray_data");

            grayDataPlotForm.ShowDialog();

            KMeansClusterizer clusterizer = new KMeansClusterizer();

            List <Dictionary <PointF, List <PointF> > > clusterizingHistory = clusterizer.Clusterize(allPoints, CLUSTER_COUNT);

            PlotForm resultPlotForm = new PlotForm(CreateClusterizingPlot(clusterizingHistory.Last()), "crusterized");

            resultPlotForm.ShowDialog();

            PlotForm historyForm = new PlotForm(clusterizingHistory.Select(c => CreateClusterizingPlot(c)).ToList(), "history_");

            historyForm.ShowDialog();

            CentroidLinkage <DataPoint> linkage = new CentroidLinkage <DataPoint>(
                new DissimilarityMetric(),
                cluster => new DataPoint(
                    cluster.Average(p => p.X),
                    cluster.Average(p => p.Y)
                    )
                );
            AgglomerativeClusteringAlgorithm <DataPoint> algorithm = new AgglomerativeClusteringAlgorithm <DataPoint>(linkage);

            HashSet <DataPoint>          dataPoints       = allPoints.Select(p => new DataPoint(p)).ToHashSet();
            ClusteringResult <DataPoint> clusteringResult = algorithm.GetClustering(dataPoints);
            ClusterSet <DataPoint>       result           = clusteringResult[clusteringResult.Count - 3];

            Plot aglomeraPlot = new Plot();

            foreach (Cluster <DataPoint> resultCluster in result)
            {
                Color color = aglomeraPlot.GetNextColor();

                aglomeraPlot.AddScatterPoints(
                    resultCluster.Select(p => (double)p.X).ToArray(),
                    resultCluster.Select(p => (double)p.Y).ToArray(),
                    color
                    );

                aglomeraPlot.AddPoint(
                    resultCluster.Select(p => p.X).Average(),
                    resultCluster.Select(p => p.Y).Average(),
                    color, 25
                    );
            }

            PlotForm aglomeraForm = new PlotForm(aglomeraPlot, "aglomera");

            aglomeraForm.ShowDialog();

            clusteringResult.SaveD3DendrogramFile(Environment.CurrentDirectory + "/dendro.json");

            Console.ReadLine();
        }