0
$\begingroup$

I have to lists, xcor and ycor that contain the $x$-axis and $y$-axis coordinates of $N$ nodes. The nodes are divided into $C$ non overlapping clusters. The clustering information is provided in a binary matrix $Mmat$ of size $C\times N$, where $C$ is the number of clusters. If $M_{c,n}=1$, then node $n$ belongs to cluster $c$.

How can I show the clusters graphically?

xcor = {0.0667, 0.1667, 0.1667, 0.1667, 0.1667, 0.1667, 0.5000, 0.5000, 0.5000, 0.3000, 0.5000, 0.5000, 0.8333, 0.8333, 0.8333, 0.8333, 0.8333, 0.8333, 1.1667, 1.0667, 1.1667, 1.1667, 1.1067, 1.1667, 1.3000, 1.5000, 1.4000, 1.5000, 1.6000, 1.5000, 1.7333, 1.8333, 1.5333, 1.8333, 1.7333, 1.6333};

ycor = {0.1667, 0.4000, 0.8333, 1.1067, 1.5000, 1.6333, 0.1667, 0.4000, 0.8333, 1.1667, 1.5000, 1.8333, 0.1667, 0.5000, 0.8333, 1.1667, 1.5000, 1.7333, 0.1667, 0.5000, 0.7333, 1.1667, 1.4000, 1.8333, 0.1667, 0.5000, 0.8333, 1.1667, 1.5000, 1.8333, 0.1667, 0.5000, 0.7333, 1.1467, 1.5000, 1.6333};

Mmat = {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,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> Range[Length @ positions]]

enter image description here

lp2 = ListPlot[Extract[xy, List /@ positions]] /. 
   p_Point :> {Dynamic@EdgeForm[{Thin, CurrentValue["Color"]}], 
     Opacity[.2], Polygon@p[[1]]};

Show[lp, lp2]

enter image description here

lp3 = ListPlot[Extract[xy, List /@ positions]] /. 
   p_Point :> {Dynamic @ EdgeForm[{Thin, CurrentValue["Color"]}], Opacity[.2], 
    MeshPrimitives[ConvexHullMesh[Join @@ 
      (MeshCoordinates[DiscretizeRegion@Circle[#, .05]] & /@  p[[1]])], 2]};

Show[lp, lp3]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks a lot. This is exactly what I need! $\endgroup$
    – MGK
    May 4, 2021 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.