I know it is perfectly possible to show the bivariate probability distributions in MMA. But my question is can we show each dimension of distribution in 2D dimension while we are showing the 3D plot? The same as here:
How we can have the 2D histograms in the sides and 3D histogram in between?
Answer
You can also try this:
Generate yor data:
data = RandomVariate[\[ScriptD] =
MultinormalDistribution[{0, 0}, {{1, 0.9}, {0.9, 2}}], 10^4];
To improve a little bit the final image, you might want to introduce lighting vectors:
lightSources = {
{"Directional", White,Scaled[{1, 0, 1}]},
{"Directional", White,Scaled[{1, .5, 1}]},
{"Directional", White, Scaled[{.5, 0, 1}]}
};
Create the 3D histogram
G1 = Histogram3D[data, {0.25}, "PDF", ColorFunction -> "Rainbow",
PlotRange -> {{-4, 4}, {-4, 4}, All}, ImageSize -> Medium,
Boxed -> False, Lighting -> lightSources]
Create the individual histograms
G3 = Histogram[Transpose[data][[1]], {-4, 4, .25}, "Probability",
ColorFunction -> Function[{height}, ColorData["Rainbow"][height]],
Axes -> False]
G4 = Histogram[Transpose[data][[2]], {-4, 4, .25}, "Probability",
ColorFunction -> Function[{height}, ColorData["Rainbow"][height]],
Axes -> False]
Show them all together:
G5 = Graphics3D[{EdgeForm[], Texture[G3],
Polygon[{{4, 4, 0}, {-4, 4, 0}, {-4, 4, 0.2}, {4, 4, 0.2}},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]},
Axes -> False, Boxed -> False];
G6 = Graphics3D[{EdgeForm[], Texture[G4],
Polygon[{{-4, 4, 0}, {-4, -4, 0}, {-4, -4, 0.2}, {-4, 4, 0.2}},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]},
Axes -> False, Boxed -> False];
Show[G1, G5, G6]
EDITED
If you want a strict 2D representation of the data you can try this:
DH = DensityHistogram[data, {-4, 4, .25}, ColorFunction -> "Rainbow", Frame -> False];
GraphicsGrid[{{G3,}, {DH, Rotate[G4, -.5 Pi]}}]
Comments
Post a Comment