6
$\begingroup$

I would like to make a 3D bubble chart with an aspect ratio of 0.3. But when I give BubbleChart3D the option AspectRatio -> 0.3, the bubbles aspect ratio also changes, squashing the bubbles. I have wasted much time and I didn't get the desired result. I tried to apply functions like Scale and set BoxRatios but didn't get a positive result.

original after the change

How can I cope with this problem?

BubbleChart3D[
 {Join[mean[[;; , ;; 3]], Partition[σ, 1], 2]}~Flatten~1
 , Axes -> True
 , AxesEdge -> {{-1, -1}, {-1, -1}, {-1, -1}}
 , AxesLabel -> {"X", "Y", "Z"}
 , BubbleScale -> "Diameter"
 , ViewVertical -> {0, 1, 0}
 , ViewPoint -> {-1, 0., 0.}
 , FaceGrids -> {{0, 0, -1}, {0, -1, 0}}
 , FaceGridsStyle -> Directive[Gray, Dashed]
 , Boxed -> True
 , ColorFunction -> (GrayLevel[0.7 - 0.7 #1, 0.7] &)
 , Lighting -> 
     {{"Ambient", LightGray}, {"Directional", Gray, {20000, 15000, 100000}}}
 , AspectRatio -> 0.3
 , BoxRatios -> Automatic
 , ImageSize -> {600, 200}
 ]
$\endgroup$
7
$\begingroup$

Here is another way to do it. I define a chart element function that makes the bubbles ellipsoids having principal axes calculated to reverse the distortion introduced by changing the z-axis box ratio.

coords = Flatten[CoordinateBoundingBoxArray[{{0, 0, 0}, {3, 3, 2}}], 2];
SeedRandom[42]; vals = RandomReal[1, Length@coords];
bubbles = MapThread[{Sequence @@ #1, #2} &, {coords, vals}];

With[{zAspect = .3, λ = .2}},
  BubbleChart3D[bubbles,
    ChartElementFunction -> 
      (Ellipsoid[#2[[;; 3]], λ #2[[4]] {1, 1, 1/zAspect/GoldenRatio}] &),
    Axes -> True,
    AxesEdge -> {{-1, -1}, {-1, -1}, {-1, -1}},
    AxesLabel -> {"X", "Y", "Z"},
    BubbleScale -> "Diameter",
    FaceGridsStyle -> Directive[Gray, Dashed],
    Boxed -> True,
    ColorFunction -> (GrayLevel[.3 + .7 (1 - #1), 0.5] &),
    Lighting -> "Neutral",
    BoxRatios -> {1, 1, zAspect},
    PlotRangePadding -> Scaled[.04],
    ImageSize -> 500]]

bubbles

$\endgroup$
8
$\begingroup$

A somewhat hacky fix is to inspect what's inside and change it:

postprocessBubbleChart3D[in_] := 
  With[{br = Quiet[BoxRatios /. AbsoluteOptions[in, BoxRatios]]},
    (
      in /. GeometricTransformation3DBox[{s_SphereBox}, {m_?MatrixQ, v_}] :> 
        GeometricTransformation3DBox[s, {m/br, v}]

    ) /; VectorQ[br]
  ]

postprocessBubbleChart3D[in_] := in

Some fake data:

chart = BubbleChart3D[Select[RandomReal[1, {50, 4}], Min[#[[2]], #[[3]]] > 0.5 &], BoxRatios -> Automatic];

Test:

{chart, postprocessBubbleChart3D[chart]}

enter image description here

$\endgroup$

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.