3
$\begingroup$

My final goal is to get coordinate grid on the z=0 plane of BarChart3D. The provided FaceGrid is not suitable as it would be below the lowest bar.

I tried to do draw the grid using graphics primitives but I failed to get desired result. The surrounding box tries to include my tick labels and it does not look so good. Here my minimal example:

ρ = 1/2 ( {
     {1, 0, 0, -1},
     {0, 0, 0, 0},
     {0, 0, 0, 0},
     {-1, 0, 0, 1}
    } );

Show[{
  BarChart3D[ρ,
   Boxed -> True,
   BarSpacing -> {1, 1},
   ChartLayout -> "Grid",
   FaceGrids -> None,
   Axes -> {True, True, True},
   ViewPoint -> {1, -5, 3},
   Method -> {"Canvas" -> None},
   Ticks -> {
     Range[-10, 10, 2],
     Range[-10, 10, 2],
     Range[-10, 10, 2]
     }
   ],
  Graphics3D[{
    Table[Text[y, {10, y 2 - 1.5, 0}], {y, 1, 4}],
    Table[Line[{{-4, y 2 - 1.5, 0}, {10, y 2 - 1.5, 0}}], {y, 1, 4}]
    }]
  }]

BarChart3D with bad box

What I want is the plot labels outside of the surrounding box, not inside. The funny thing is, that for example ListPlot3D there is no such effect and thus there is something in Graphics3D which I do not understand. Let me give an example:

Show[{
  ListPlot3D[{{0, 0, 0}, {0, 0, 0}},
   PlotRange -> {{-1, 8}, {-1, 8}, {-0.5, 0.5}},
   Boxed -> True,
   FaceGrids -> None,
   Axes -> {True, True, True},
   ViewPoint -> {1, -5, 3},
   Ticks -> {
     Range[-10, 10, 2],
     Range[-10, 10, 2],
     Range[-10, 10, 2]
     }],
  BarChart3D[ρ,
   BarSpacing -> {1, 1},
   ChartLayout -> "Grid",
   FaceGrids -> None,
   Method -> {"Canvas" -> None}
   ],
  Graphics3D[{
    Table[Text[y, {10, y 2 - 1.5, 0}], {y, 1, 4}],
    Table[Line[{{-4, y 2 - 1.5, 0}, {10, y 2 - 1.5, 0}}], {y, 1, 4}]
    }]
  }]

enter image description here

  • Why does ListPlot3D and BarChart3D act differently,
  • how to get the elements out of surrounding box in more clean way than wrapping it with ListPlot3D and
  • perhaps there is a more elegant way to get "cityline bar charts" with z=0 plane coordinate grid & ticks.
$\endgroup$
3
$\begingroup$

When combining objects with Show, the option that was specified first will be used for the entire display, unless it is overridden in the options to Show itself. Now look at the PlotRange option specifically for the two objects BarChart3D and ListPlot3D that you created (I give them individual names here):

bc = 
  BarChart3D[ρ, Boxed -> True, BarSpacing -> {1, 1}, 
   ChartLayout -> "Grid", FaceGrids -> None, 
   Axes -> {True, True, True}, ViewPoint -> {1, -5, 3}, 
   Method -> {"Canvas" -> None}, 
   Ticks -> {Range[-10, 10, 2], Range[-10, 10, 2], Range[-10, 10, 2]}];

lp = 
  ListPlot3D[{{0, 0, 0}, {0, 0, 0}}, 
   PlotRange -> {{-1, 8}, {-1, 8}, {-0.5, 0.5}}, Boxed -> True, 
   FaceGrids -> None, Axes -> {True, True, True}, 
   ViewPoint -> {1, -5, 3}, 
   Ticks -> {Range[-10, 10, 2], Range[-10, 10, 2], Range[-10, 10, 2]}];

Options[bc, PlotRange]

(* ==> {PlotRange -> All} *)

Options[lp, PlotRange]

(* ==> {PlotRange -> {{-1, 8}, {-1, 8}, {-0.5, 0.5}}} *)

The BarChart3D has the option set to All, which we don't want. By adding the ListPlot3D as the first element in Show, you simply override that setting with the last line.

This immediately tells us how to get the same effect without adding the empty ListPlot3D: just specify the desired limited PlotRange in BarChart3D:

Show[{BarChart3D[ρ, 
   PlotRange -> {{-1, 8}, {-1, 8}, {-0.5`, 0.5`}}, Boxed -> True, 
   BarSpacing -> {1, 1}, ChartLayout -> "Grid", FaceGrids -> None, 
   Axes -> {True, True, True}, ViewPoint -> {1, -5, 3}, 
   Method -> {"Canvas" -> None}, 
   Ticks -> {Range[-10, 10, 2], Range[-10, 10, 2], 
     Range[-10, 10, 2]}], 
  Graphics3D[{Table[Text[y, {10, y 2 - 1.5, 0}], {y, 1, 4}], 
    Table[Line[{{-4, y 2 - 1.5, 0}, {10, y 2 - 1.5, 0}}], {y, 1, 
      4}]}]}]

barchart3d

$\endgroup$
  • $\begingroup$ Damn. I spent 5 hours on this thing and in the end it turned out to be difference in default values. Thanks! $\endgroup$ – Johu Aug 15 '15 at 6:59

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.