Colorinformation of ContourPlot3D

For a given plot (unknown Colorfunction) bild I would like to get the color of every single point {x,y,z}.

bild = ContourPlot3D[x^3 + y^2 - z^2, {x, -2, 2}, {y, -2, 2}, {z, -2, 2},
ColorFunction -> Function[{x, y, z}, Hue[x^2 + y^2 + z^2]],
Mesh -> False]


I tried

pts=bild[[1, 1]][[1]]
Cases[ bild , VertexColors -> col_  :> col, -1] (* { } *)


which returns an empty set.

Any idea? Thanks!

• It may help to try with bild = ContourPlot3D[x^3 + y^2 - z^2, {x, 0, 1}, {y, 0, 1}, {z, 0, 1}, Contours -> 1, ColorFunction -> Function[{x, y, z}, Hue[x^2 + y^2 + z^2]], Mesh -> False,PlotPoints->5] Commented Dec 27, 2023 at 11:49
• it seems then this works? tt = bild // FullForm // First // First // First; pts = tt[[1]]; col = tt[[3, 2]]; Transpose[{col, Map[Point, pts]}] // Graphics3D Commented Dec 27, 2023 at 11:55

This also works but is probably less robust. It does not require redoing the plot though.

tt = bild // FullForm // First // First // First;
pts = tt[[1]]; col = tt[[3, 2]];
Transpose[{col, Map[Point, pts]}] // Graphics3D


• Thanks for your answer and effort. VertexColor only gives a scalar as color information, I would have expected an RGB-triple Any idea how to interpret this scalar? Commented Dec 27, 2023 at 12:50
• I am not sure I understand: col[[1]] // Head returns Hue. Commented Dec 27, 2023 at 12:55
• Thanks, meanwhile I can reproduce your result! Commented Dec 27, 2023 at 13:00

You may try with Sow and Reap.

{bild, pts} =
Reap[ContourPlot3D[
x^3 + y^2 - z^2, {x, -2, 2}, {y, -2, 2}, {z, -2, 2},
ColorFunction ->
Function[{x, y, z}, Sow[{Hue[x^2 + y^2 + z^2], {x, y, z}}];
Hue[x^2 + y^2 + z^2]], Mesh -> False]];

Graphics3D[MapAt[Point, First@pts, {All, 2}]]


• Thanks for this clear answer! Commented Dec 27, 2023 at 13:05
• It is astonishing that ContourPlot3D generates far fewer points here than in chris's answer Commented Dec 27, 2023 at 13:37
• @UlrichNeumann, I believe he set PlotPoints -> 50 (which I did not) – that's why he got more points :) Commented Dec 27, 2023 at 13:58
stylePointPairs = Cases[Normal[bild],
Polygon[coords_, VertexColors -> cols_, ___] :>

Graphics3D[{PointSize@Medium, stylePointPairs}]


You can also use:

stylePointPairs2 = Cases[bild,
GraphicsComplex[coords_, ___, VertexColors -> cols_, ___] :>

Graphics3D[{PointSize@Medium, stylePointPairs2}]


Normal[bild] /.
{_Line -> {},
Polygon[coords_, vc : (VertexColors -> _), ___] :>
{PointSize @ Medium, Point[coords, vc]}}


• Thanks for your answer! Any idea why Cases[ bild , VertexColors -> col_ :> col, -1] doesn't work? Commented Dec 27, 2023 at 13:59
• @UlrichNeumann, we need to use Cases[bild, (VertexColors -> col_) :> col, -1] or Cases[bild, HoldPattern[(VertexColors -> col_)]:> col, -1]
– kglr
Commented Dec 27, 2023 at 14:04
• Check VertexColors -> col_ :> col // FullForm to see how VertexColors -> col_ :> col is parsed.
– kglr
Commented Dec 27, 2023 at 14:06