public void ExecuteRecipe(Plot plt) { double[] xs = DataGen.Consecutive(51); double[] ys = DataGen.Sin(51); plt.AddScatterPoints(xs, ys, Color.Navy, 10, MarkerShape.filledDiamond); }
public void ExecuteRecipe(Plot plt) { Random rand = new Random(0); double[] xs = DataGen.Random(rand, 50); double[] ys = DataGen.Random(rand, 50); var scatter = plt.AddScatterPoints(xs, ys, Color.Blue, 10); var vlines = new ScottPlot.Plottable.VLineVector(); vlines.Xs = new double[] { xs[1], xs[12], xs[35] }; vlines.Color = Color.Red; vlines.PositionLabel = true; vlines.PositionLabelBackground = vlines.Color; var hlines = new ScottPlot.Plottable.HLineVector(); hlines.Ys = new double[] { ys[1], ys[12], ys[35] }; hlines.Color = Color.DarkCyan; hlines.PositionLabel = true; hlines.PositionLabelBackground = hlines.Color; hlines.DragEnabled = true; plt.Add(scatter); plt.Add(vlines); plt.Add(hlines); }
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); }
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(); }