3
$\begingroup$

Bassicaly I work with the points in data and try to find clusters with different distance functions and show them in the grid.But,how can I add the plot markers "OpenMarkers" like with plot legend in the grid plot? Here is what I have done.

data = {{-1.1, 2.6}, {3.9, -0.8}, {4.2, -3.7}, {3.3, 3.5}, {3.9, 
    5.2}, {4.1, -4.8}, {3.8, 3.7}, {5.6, 0.1}, {3.1, -5.2}, {-0.9, 
    2.3}, {2.9, 4.1}, {-2.3, 3.9}, {-2.5, 3.}, {2.6, -5.5}, {5.2, 
    1.9}, {-0.7, 1.3}, {0.9, 2.8}, {-1.5, 3.3}, {3.8, 
    1.2}, {2.6, -5.1}, {-0.8, 3.2}, {4.7, 0.7}, {3., 3.}, {3.9, 
    3.6}, {4.5, 1.4}, {4.2, 1.3}, {-1.1, 2.6}, {4.8, 
    2.4}, {3.3, -3.5}, {3.2, -4.6}, {3.3, -4.9}, {3., 3.5}, {0.7, 
    2.1}, {3.2, -4.3}, {-2., 0.5}, {-1.2, 2.}, {-1.6, 1.8}, {-3.5, 
    3.7}, {4.8, 0.2}, {3.3, 2.4}, {-0.1, 2.1}, {-1.3, 2.5}, {4.4, 
    3.9}, {3.5, 0.2}, {0.1, 2.9}, {-1., 1.6}, {-1.4, 4.5}, {3.2, 
    2.5}, {-1.6, 2.4}, {2.6, -5.1}};

Plot1 = ListPlot[
   FindClusters[data, 2, DistanceFunction -> ChebyshevDistance], 
   PlotMarkers -> "OpenMarkers", PlotLegends -> Automatic];
Plot2 = ListPlot[
   FindClusters[data, 2, 
    DistanceFunction -> SquaredEuclideanDistance], 
   PlotMarkers -> "OpenMarkers", PlotLegends -> Automatic];
Plot3 = ListPlot[
   FindClusters[data, 2, DistanceFunction -> EuclideanDistance], 
   PlotMarkers -> "OpenMarkers", PlotLegends -> Automatic];

   Legended[Grid[{{Plot1, Plot2}, {Plot3, None}}], 
 PointLegend[{ColorData[97, 101], 
   ColorData[97, 102]}, {"\[EmptySmallCircle]", "\[EmptyUpTriangle]"}]]

I try to use Legended and PointLegended with the marker symbol but without succes.

enter image description here

$\endgroup$

2 Answers 2

4
$\begingroup$
nc = 2;
labels = {"cluster 1", "cluster 2"};

plots = ListPlot[FindClusters[data, 2, DistanceFunction -> #], 
        PlotMarkers -> "OpenMarkers"] & /@ 
    {ChebyshevDistance, SquaredEuclideanDistance, EuclideanDistance};

legend = PointLegend[97, 
    MapThread[Style[##, 16] &, {labels, ColorData[97] /@ Range[Length@labels]}], 
    LegendMarkers -> "OpenMarkers"];

Legended[Multicolumn[plots, 2], legend]

enter image description here

or

Legended[Grid @ Partition[plots, 2, 2, 1, {}], legend]

same picture

Use

nc = 3;
labels = {"cluster 1", "cluster 2",, "cluster 3"};

to get

enter image description here

$\endgroup$
3
$\begingroup$

If the intent is to have a common legend

Partition[
  Append[
   ListPlot[
      FindClusters[data, 2,
       DistanceFunction -> #],
      PlotMarkers -> "OpenMarkers",
      PlotLabel -> #] & /@
    {ChebyshevDistance,
     SquaredEuclideanDistance,
     EuclideanDistance},
   Column[{
     Style["○  Cluster 1", 16, Bold, ColorData[97][1]],
     Style["△  Cluster 2", 16, Bold, 
      ColorData[97][2]]}]], 2] // 
 Grid[#, Spacings -> {Automatic, 3}] &

enter image description here

Using Legended

Legended[
 Partition[
   Append[
    ListPlot[
       FindClusters[data, 2,
        DistanceFunction -> #],
       PlotMarkers -> "OpenMarkers",
       PlotLabel -> #] & /@
     {ChebyshevDistance,
      SquaredEuclideanDistance,
      EuclideanDistance}, ""], 2] //
  Grid[#, Spacings -> {Automatic, 3}] &,
 Placed[
  PointLegend[
   ColorData[97] /@ Range[2],
   StringForm["Cluster ``", #] & /@ Range[2],
   LegendMarkers -> {{"○", 16}, {"△", 16}}],
  {0.85, 0.2}]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Yes, thats the idea. But if I would like to expand the clusters, do I need to insert the markers manually for the legend? $\endgroup$
    – Las Des
    Commented Aug 4, 2020 at 23:25

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.