2
$\begingroup$

I have a data set with four columns, i.e. dimensions, all are numerical. The last attribute is either 0 or 1. So I want to plot the data in the following way: the first three entries are the coordinates and the determines the color (0:Red, 1: Green). I can plot this using Graphics3D like:

Example data:

list = {{1, 29., 2, 1}, {1, 0.9167, 1, 1}, {1, 2., 2, 0}, {1, 30., 1,0}, {1, 25., 2, 0}}

then:

ClearAll[plotPoint];
plotPoint[list_List] := Module[{c, a, g, s},
  {c, a, g, s} = list;
  If[s == 1,
   Graphics3D[{PointSize[Small], Green, Point[{c, a, g}]}],
   Graphics3D[{PointSize[Small], Red, Point[{c, a, g}]}]
   ]
  ]

then

Show[plotPoint /@ list]

delivers an output. What I now tried to achieve is to do this job with ListPointPlot3D to get axes and so on. But here I can only deliver a ColorFunction which takes three arguments (the coordinates) and I could not manage to get my fourth attribute (last components in data set) in there to get the coloring. Is there any way to do this?

$\endgroup$

2 Answers 2

1
$\begingroup$
list2 = Style[{#, #2, #3}, #4 /. {0 -> Red, 1 -> Green}] & @@@ list; 
ListPointPlot3D[list2, BaseStyle -> PointSize[Large]] 

enter image description here

Alternatively,

ListPointPlot3D[List /@ list[[All, ;; 3]], 
 PlotStyle -> (list[[All, 4]] /. {0 -> Red, 1 -> Green}), 
 BaseStyle -> PointSize[Large]]

same picture

$\endgroup$
1
  • $\begingroup$ Thanks a lot. O.K. when you know it - it is simple, but if not.... One of the solutions where I ask myself why I haven't seen it. $\endgroup$
    – mgamer
    Commented Oct 28, 2018 at 14:27
1
$\begingroup$

Another alternative:

Graphics3D[
 {PointSize[Large],
  Point[list[[All, ;; 3]], 
   VertexColors -> (Blend[{Red, Green}, #] & /@ list[[All, 4]])]
  },
 PlotRange -> Automatic,
 Options[ListPointPlot3D]]

Mathematica graphics

Another way to get the colors:

VertexColors -> IdentityMatrix[3][[1 + list[[All, 4]]]]
$\endgroup$
1
  • $\begingroup$ Thank you, cool application for Blend, too. $\endgroup$
    – mgamer
    Commented Oct 29, 2018 at 13:29

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.