Data plotting: problem with coloring the plots

I have a data to plot in the form of {x,y,f(x,y)}. Essentially, I have two curves (to be precise, surfaces). I want different colors for each surface. But I'm failing to do so.

Here is my datatoplot:

Graphics3D[Riffle[{Red, Blue},Point /@ Transpose[SortBy[Last] /@ Partition[datatoplot, 2]]]]

In the above plot: you see four surfaces. Actually there is a periodic boundary condition (all the faces of cuboid). So, from left corner (first red) and third (blue red combination) are the same, likewise second (blue red) and forth (blue).

PS: To be more clear. The top face and the bottom face are same. Likewise, any opposite face of the cuboid. So, the first red (on the left corner) goes and reappear on the top ( third surface) but blue and red (instead of red). Hope it's clear! But I can do it better, if it isn't

I was looking for the clever way to color them. But I don't know. • Very cool dataset. But I see 4 surfaces. – Anton Antonov Jun 2 at 19:21
• @AntonAntonov Oops! Thanks for pointing it out. Actually there is a periodic boundary condition. So, from left corner (first red) and third (blue red combination) are the same, likewise second (blue red) and forth (blue). – Shamina Jun 2 at 19:30
• I am not sure I understand. Is the plot in my answer something you expect/want? – Anton Antonov Jun 2 at 19:33
• @AntonAntonov. I'm sorry, maybe I'm talking in telepathy. You almost got it. I mean the top face and the bottom face are same. Likewise, any opposite face of the cuboid. So, the first red (on the left corner) goes and reappear on the top ( third surface) but blue and red (instead of red). Hope it's clear! But I can do it better, if it isn't – Shamina Jun 2 at 19:38

1. We find the Nearest Neighbors (NN's) graph based on the 4 closest NN's for each point.

2. We find the connected components of that graph.

3. We plot the components with some color scheme/function.

AbsoluteTiming[
gr = NearestNeighborGraph[data, 4];
ccs = ConnectedComponents[gr];
]
Length[ccs]

(* {0.110175, Null} *)
(* 4 *)

Graphics3D[
MapIndexed[{ColorData[7, "ColorList"][[#2[]]], Point[#1]} &, ccs]] I used the 4 closest Nearest Neighbors (NN's) for each point because the points patterns of the surfaces can be projected on 2D regular grids. I could have used 8 NN's, but 4 NN's seemed enough (i.e. it worked.) Because we have 4 surfaces I used 4 as the number of connected components to be identified.

Additional code / responses

Using this code we can see which surface on the plot corresponds to which element of components lists, ccs.

Graphics3D[
MapIndexed[{Text[
Style["Surface:" <> ToString[#2[]], Blue, Bold,
FontSize -> 16], Mean[#1]],
ColorData[7, "ColorList"][[#2[]]], Point[#1]} &, ccs]] And we have this plot for those components:

Graphics3D[
MapIndexed[{Text[
Style["Surface:" <> ToString[#2[]], Blue, Bold,
FontSize -> 16], Mean[#1]],
ColorData[7, "ColorList"][[#2[]]], Point[#1]} &,
ccs[[{1, 3}]]]] • I edited my question. Unfortunately, I was explaining to myself (I.e too vague in my explanation). But you almost got it! I need two days sets (containing two surfaces data), that will solve all the hurdles. I need to calculate quantities but this separation of data wasn't clear before so everything was wrong like the plot, as shown in the question – Shamina Jun 2 at 19:45
• I hope you can modify / extend the code of my answer to produce the plot you want... – Anton Antonov Jun 2 at 20:03
• I updated my answer with more explanations. – Anton Antonov Jun 3 at 12:55
• See my updated answer. – Anton Antonov Jun 3 at 17:12
• Sounds good, good luck! – Anton Antonov Jun 4 at 12:54

You can experiment with ListLinePlot3D.

ListPointPlot3D[datatoplot, ColorFunction -> Function[{x, y, z}, Hue[z]],
PlotStyle -> PointSize[0.002], ImageSize -> 800] 