1
$\begingroup$

I would like to achieve something like ArrayPlot[] but rather than using the array values for color, I want those values to specify heights of rectangular blocks. There seems to be no option in ArrayPlot to do that. Is there some good ideas to do that in ArrayPlot or in other commands? Thank you in advance.

$\endgroup$
1
  • 2
    $\begingroup$ You could use something like BarChart3D[{{1, 1, 1, 1}, {1, 2, 1, 2}, {1, 1, 3, 1}, {1, 2, 1, 4}}, ChartLayout -> "Grid"]. $\endgroup$
    – J. M.'s torpor
    Jun 14 '16 at 15:15
4
$\begingroup$

Here's a way to roll your own:

(*Some sample data.*)
data = Table[Exp[-(x^2/1 + y^2/2)], {x, -2, 2, 0.1}, {y, -2, 2, 0.1}];

(*Use colored cuboids with data as the heights.*)
  rectPlot[data_] := Module[
  {dimx, dimy},
  {dimx, dimy} = Dimensions@data;
  Graphics3D[
   Table[
    {
     Hue[data[[i, j]]/Max@data],
     Cuboid[{i, j, 0}, {i + 1, j + 1, data[[i, j]]}]
     }
    , {i, dimx}
    , {j, dimy}
    ]
   , BoxRatios -> {1, 1, 1}
   ]
  ]

rectPlot[data]

Which gives:

enter image description here

You can investigate the options for Graphics3D if this is too basic, but it's a start.

Another option is to use ListPlot3D:

ListPlot3D[
   data
   , InterpolationOrder -> 0
   , Filling -> Axis
   , ColorFunction->Hue
   , FillingStyle -> Opacity[1]
   , BoxRatios -> {1, 1, 1}
   ]

But I don't know how to color the filling on this plot.

enter image description here

$\endgroup$
1
  • 3
    $\begingroup$ Here's an alternative implementation: Graphics3D[Transpose[{Map[ColorData["TemperatureMap"], Rescale[data], {2}], MapIndexed[Cuboid[Append[#2, 0], Append[#2 + 1, #1]] &, data, {2}]}, {3, 1, 2}], BoxRatios -> {1, 1, 0.4}, Lighting -> "Classic"] $\endgroup$
    – J. M.'s torpor
    Jun 14 '16 at 16:56

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.