1
$\begingroup$

I am trying to make a 3D contour plot I calculated in c++. I read in the results as tables and used the function ListSliceContourPlot3D.

This is what I got so far

enter image description here

I want to highlight the zero regions (region with value < 0.0001) using a white color,

i.e. purple -> white

Here is my code

data3d = Import["simulation220.txt", 
   "table"];
dim = Dimensions[data3d];
l = dim[[1]]/dim[[2]]; m = dim[[2]]; n = dim[[2]];
cuboid = Table[1, {x, l}, {y, m}, {z, n}];
For[i = 1, i < l + 1, i++, a = n*(i - 1) + 1; b = n*i; 
  cuboid[[i]] = data3d[[a ;; b]]];
ListSliceContourPlot3D[cuboid, {"ZStackedPlanes", {1, 87, 174}}, 
 PlotTheme -> "Detailed", 
 ColorFunction -> ColorData[{"Rainbow", {0, 1}}], 
 Contours -> {0.0001, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9}, 
 ContourStyle -> Black, PlotRange -> {All, All, All, {-.5, 1}}, 
 Axes -> False, ClippingStyle -> White, AspectRatio -> 1.5, 
 ColorFunctionScaling -> False]

and here is my data simulation220

All the numbers in my data are positive.

$\endgroup$

2 Answers 2

2
$\begingroup$
threshold = .0001;
contours = {threshold, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9};

1. ContourShading

contourshading = Prepend[ConstantArray[Automatic, Length[contours]], White];

ListSliceContourPlot3D[cuboid, {"ZStackedPlanes", {1, 87, 174}}, 
 PlotTheme -> "Detailed", 
 ColorFunction -> ColorData[{"Rainbow", {0, 1}}],
 ContourShading -> contourshading, 
 Contours -> contours, ContourStyle -> Black, 
 PlotRange -> {All, All, All, {-.5, 1}}, Axes -> False, 
 AspectRatio -> 1.5, ColorFunctionScaling -> False]

enter image description here

2. Custom color function:

cf = If[# <= threshold, White, ColorData[{"Rainbow", {0, 1}}][#]] &;

ListSliceContourPlot3D[cuboid, {"ZStackedPlanes", {1, 87, 174}}, 
 PlotTheme -> "Detailed", 
 ColorFunction -> cf,
 Contours -> contours, ContourStyle -> Black, 
 PlotRange -> {All, All, All, {-.5, 1}}, Axes -> False, 
 AspectRatio -> 1.5, ColorFunctionScaling -> False]

enter image description here

$\endgroup$
0
$\begingroup$

One way is to use a Blend of "Rainbow" colors with purple threshold set to 0.0001.

colorFunction = Blend[{
{0.0001, RGBColor[1., 0.99997, 0.999985]}, {0.0625, 
 RGBColor[0.31106, 0.11758, 0.664469]},
{0.125, RGBColor[0.250728, 0.225386, 0.769152]}, {0.1875, 
 RGBColor[0.24408, 0.361242, 0.816084]},
{0.25, RGBColor[0.266122, 0.486664, 0.802529]}, {0.3125, 
 RGBColor[0.305919, 0.585575, 0.739666]},
{0.375, RGBColor[0.36048, 0.655759, 0.645692]}, {0.4375, 
 RGBColor[0.429842, 0.701849, 0.540321]},
{0.5, RGBColor[0.513417, 0.72992, 0.440682]}, {0.5625, 
 RGBColor[0.607651, 0.743718, 0.358588]},
{0.625, RGBColor[0.705038, 0.742591, 0.299167]}, {0.6875, 
 RGBColor[0.794549, 0.721158, 0.260829]},
{0.75, RGBColor[0.863512, 0.670771, 0.236564]}, {0.8125, 
 RGBColor[0.901014, 0.582826, 0.216542]},
{0.875, RGBColor[0.902853, 0.453964, 0.192014]}, {0.9375, 
 RGBColor[0.878107, 0.293208, 0.160481]},
{1., RGBColor[0.857359, 0.131106, 0.132128]}}, #1] &

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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