Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Suppose we have an array of color data

colorArray = ParallelTable[With[{v = RandomReal[]},
Append[List @@ ColorData["LightTemperatureMap"][v], If[v >= .8, .5, 0]]
], {z, 0, .1, .005}, {y, 0, 1, .1}, {x, 0, 10, 2}];

And we use Image3D to visualize them

is = 350;
Image3D[
colorArray, "Real", ColorSpace -> "RGB",
ViewPoint -> {1.3, -2.4, 2}, SphericalRegion -> True,
Boxed -> True, BoxRatios -> {1, 1, 1},
Axes -> True, AxesLabel -> {"X", "Y", "Z"},
ImageSize -> is, ImageResolution -> 3*is]

enter image description here

The problem is that the ticks are the relative position of each RGBColor element in the array, not the actual range of x, y, and z ({z, 0, .1, .005}, {y, 0, 1, .1}, {x, 0, 10, 2}). My question is how can we change the ticks to show the actual range of x, y, and z? A direct implement seems impossible because in colorArray no data about the original x, y, and z values are stored (actually we cannot store them in colorArray due to the requirement of Image3D).

share|improve this question
1  
Have you seen Raster3D? This allows you to specify the range of x, y and z. –  Simon Woods Nov 6 '13 at 9:52
    
@Simon Woods, Yes I know it, but the Image3D has better plot quality for medium sized bins, so I wish there could be a solution for Image3D. I have tried to extract a bare frame and use Show to combine it and the 3D image, but that did not work. –  saturasl Nov 6 '13 at 17:56
add comment

1 Answer

up vote 5 down vote accepted

Image3D is buggy, doesn't have all the options that other Graphics3D objects have, but we can work with it. The strategy here is to change the tickmarks in an empty ContourPlot3D and then use Show to combine it with the Image3D.

Of course, you can edit the tickmarks manually but I like to use the CustomTicks package, available here: http://library.wolfram.com/infocenter/Demos/5599/ It makes it really easy to rescale the tickmark values. Just download the CustomTicks.m file and place it somewhere in your $Path.

<< "CustomTicks`"

colorArray = 
  ParallelTable[
   With[{v = RandomReal[]}, 
    Append[List @@ ColorData["LightTemperatureMap"][v], 
     If[v >= .8, .5, 0]]], {z, 0, .1, .005}, {y, 0, 1, .1}, {x, 0, 10,
     2}];

{zdim, ydim, xdim} = Dimensions[colorArray][[;; 3]];

is = 350;
arrayplot = 
  Image3D[colorArray, "Real", ColorSpace -> "RGB", 
   ViewPoint -> {1.3, -2.4, 2}, SphericalRegion -> True, 
   Boxed -> True, BoxRatios -> {1, 1, 1}, Axes -> True, 
   AxesLabel -> {"X", "Y", "Z"}, ImageSize -> is, 
   ImageResolution -> 3*is];

{zmax, ymax, xmax} = {0.1, 1.0, 10.0};
dummyplot = 
  ContourPlot3D[x, {x, 0, xdim}, {y, 0, ydim}, {z, 0, zdim}, 
   Contours -> {-1}, PlotRange -> {{0, xdim}, {0, ydim}, {0, zdim}}, 
   Ticks -> {LinTicks[0, 10, 
      TickPostTransformation -> (# xdim/xmax &)], 
     LinTicks[0, 1, TickPostTransformation -> (# ydim/ymax &)], 
     LinTicks[0, .1, TickPostTransformation -> (# zdim/zmax &)]}, 
   AxesLabel -> {"X", "Y", "Z"}];

Show[dummyplot, arrayplot]

enter image description here

share|improve this answer
1  
Perfect solution, thank you! –  saturasl Nov 6 '13 at 20:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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