9
$\begingroup$

I've found that RegionFunction and VertexColors don't work together.

Example:

data = Flatten[
   Table[ {x/100, y/100, Sin[2 Pi x/100] Cos[2 Pi y/100]}, {x, 
     100}, {y, 100}], 1];
colorvals = (Sqrt[2] N[Norm[#[[1 ;; 2]] - {1, 1}/2]] & /@ data);
ListPlot3D[data, VertexColors -> Hue /@ colorvals]

enter image description here

Adding RegionFunction suppresses the colors..

ListPlot3D[data,
 VertexColors -> colors, 
 RegionFunction -> Function[{x, y, z}, Norm[{x, y}] < 1]]

enter image description here

Any work-around?

My actual data is not on a regular grid, and the region is not convex, if that matters.

Edit: I should have said, my actual color data is already tabular, there is no analytic function to work with as in the example.


Edit: in case anyone comes across this for discrete color values, create an interpolating function:

int = Interpolation[Transpose[{data[[All, ;; 2]], colorvals}], 
         InterpolationOrder -> 1];

then use ColorFunction -> (Hue[int[#1, #2]] &) in @paw's answer (This will likely generate some extrapolation warnings, so use Quiet )

$\endgroup$
1
  • $\begingroup$ Indeed, if you look at the InputForm[] of the second plot, no Hue[] objects can be found; thus, the explicit color setting is being ignored in that case. $\endgroup$ – J. M.'s ennui Oct 26 '15 at 17:57
5
$\begingroup$

You can use ColorFunctionto get around this issue.

ListPlot3D[data, 
 RegionFunction -> Function[{x, y, z}, Norm[{x, y}] < 1], 
 ColorFunction -> Function[{x, y, z}, Hue[Sqrt[2] N[Norm[{x, y} - {1, 1}/2]]]]
]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ great! I had to use an interpolating function since my data is given in tabular form (I suppose I should have said that..), but this does the job. $\endgroup$ – george2079 Oct 26 '15 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.