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.

I've generated a simple 3D histogram, where the x-y coordinates corresponding to the "location" of an event defined on a simple 160x160 grid, and the z-axis height is simply the count of events that occur at each x-y location.

For this particular graph, I have an png image (think of it as a map) on which the 160x160 grid is defined. I'd like to use this image as the x-y floor of my Histogram3D. I'd also like to use a ListContourPlot as the x-y floor, in a companion image.

Any suggestions would be most welcome.



share|improve this question
Have a look at this. –  b.gatessucks Feb 12 '13 at 21:32
add comment

marked as duplicate by Jens, belisarius, Sjoerd C. de Vries, Oleksandr R., m_goldberg Feb 13 '13 at 5:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

Basically you can use Show to combine your Histogram3D object with a Graphics3D object. I use a Polygon with a Texture on it to hold the image. To make the image more visible you can set the opacity level of the Histogram3D:

Show[Histogram3D[RandomReal[{0, 1}, {50, 2}], 
  ChartBaseStyle -> Opacity[0.4]], 
  Graphics3D[{Texture[ExampleData[{"TestImage", "Lena"}]],
  Polygon[{{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}}, 
  VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}]]

The above code gives the following representation:

enter image description here

The only thing you have to adjust for your particular case is to set the position of the polygon according to your data. Hope this helps, cheers.

share|improve this answer
add comment

Another variation using Texture:

 data = RandomVariate[NormalDistribution[0, 1], {100, 2}];

 {g, {binCounts}} =  Reap[Histogram3D[data, {-2, 2, 0.25}, 
  Function[{xbins, ybins, counts}, Sow[counts]]]];
img1 = Image[MatrixPlot[First@binCounts, Frame -> False, Axes -> False, 
 ColorFunction -> Hue, PlotRangePadding -> 0, ImagePadding -> 0, 
 DataReversed -> True,ImageSize -> 400]];
img2 = ExampleData@{"TestImage", "Peppers"};
hst3D = Histogram3D[data, {-2, 2, 0.25},  Function[{xbins, ybins, counts}, counts], 
Boxed -> False, Axes -> False,(* Background -> Black,*)
ChartBaseStyle -> Opacity[.3], ChartStyle -> Green,
PlotRangePadding -> 0, ImagePadding -> 0,  ImageSize -> 400]; 
Grid[{{hst3D, img1}, 
Graphics3D[{hst3D[[1]], Texture[#], Opacity[.6], EdgeForm[], 
  Polygon[{Scaled@{0, 0, 0}, Scaled@{0, 1, 0}, Scaled@{1, 1, 0}, Scaled@{1, 0, 0}}, 
   VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]},
  hst3D[[2]]] & /@{img1, img2}}, Dividers -> All]

enter image description here

share|improve this answer
add comment

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