Mathematica Label Graphics

I have a dataset with labels that I would like to build with dots colored according to their label. Is there an easy way to get the current line number inside the graph so that I can determine which category the point belongs to?

I realized that x,y,zthese are the coordinates of the constructed data, but this does not help for external shortcuts.

This is pretty ugly and it only works on a sorted dataset with regular distribution.

    data = Import["http://ftp.ics.uci.edu/pub/machine-learning-databases/iris/iris.data"];
    data = Drop[data, -1]; (*there one extra line at the end*)
    inData = data[[All, 1 ;; 4]];
    labels = data[[All, 5]];
    ListPlot3D[inData,
      ColorFunction -> 
        Function[{x, y, z}, 
          If[y < 0.33, RGBColor[1, 1, 0.], 
               If[y < 0.66, RGBColor[1, 0, 0.], RGBColor[1, 0, 1]]
          ]
        ]
    ]

Expected Result:

expected result of visualization

+5
source share
2 answers

Suppose that pointsthese are lists of coordinates and a labelslist of corresponding labels, for example,

points = Flatten[Table[{i, j, Sin[i j]}, 
   {i, 0, Pi, Pi/20}, {j, 0, Pi, Pi/10}], 1];
labels = RandomChoice[{"label a", "label b", "label c"}, Length[points]];

, , .

rules = {"label a" -> RGBColor[1, 1, 0], 
   "label b" -> RGBColor[1, 0, 0], "label c" -> RGBColor[1, 0, 1]};

, ,

ListPointPlot3D[Pick[points, labels, #] & /@ Union[labels], 
   PlotStyle -> Union[labels] /. rules]

plot

Edit

ListPlot3D, VertexColors,

ListPlot3D[points, VertexColors -> labels /. rules, Mesh -> False]

coloring points in a ListPlot3D

+5

:

(* Build the labeled structure and take a random permutation*)
f[x_, y_] = Sqrt[100 - x x - y y];
l = RandomSample@Flatten[{Table[{{"Lower", {x, y, f[x, y] - 5}},
                                 {"Upper", {x, y, 5 - f[x, y]}}},
                          {x, -5, 5, .1}, {y, -5, 5, .1}]}, 3];
(*Plot*)

Graphics3D[
 Riffle[l[[All, 1]] /. {"Lower" -> Red, "Upper" -> Green}, 
  Point /@ l[[All, 2]]], Axes -> True]

enter image description here

+3

All Articles