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.

Note: This is a version 9.0.0 problem that is fixed in 9.0.1.


I want to generate a simple 3D view of some frequencies for two variables. I have the counts in a 4x3 matrix, say. This is my bar chart code:

BarChart3D[
 Map[Labeled[#, Text[Style[#, Black, Opacity[1.], Bold, 20]], 
    Above] &, {{1, 0, 2}, {0, 0, 2}, {2, 1, 0}, {0, 2, 1}}, {2}],
 ChartLayout -> "Grid",
 BarSpacing -> Large,
 ChartElements -> Graphics3D[Cylinder[]],
 ChartStyle -> Directive[Opacity[0.3]],
 AxesLabel -> {None, None, None},
 Ticks -> {{{1/2, "Del"}, {2, "Nor"}, {2 + 3/2, "Amp"}},
   {{1/2, "Osteo"}, {1.75, "Ewing"}, {3, "Rhabdo"}, {4.25, 
     "Neuro"}}, {0, 1, 2}},
 ViewPoint -> {1.3`, -2.4`, 2.`}
 ]

And this is what I got with Mathematica 9.0 (more precisely, 9.0.0.0 Mac OS X.)

Mathematica graphics

  • First, for readability, I want to place a label in each column. But as you can see, zeroes are not displayed. How can I get BarChart3D to plot my zeros? Or probably better, to draw a flat disk in corresponding place.
  • (Not as important) Notice how I placed the ticks for the x and y axes. The matrix is 4x3, so I don't understand where those positions come from (the ones I had to use to put the labels - see Ticks above). My guess is that my positions are probably wrong, although visually seem ok for now.

Help would be much appreciated.

Update

As workaround for zeros, I put a If[#==0,0.01,Labeled[...]] in Map and displays ok. Still, I am intrigued on how to position tick labels correctly, with Ticks or some other option.

share|improve this question
    
Please, what version are you using? This is apparently version specific. –  Mr.Wizard Jan 30 at 12:00
    
I remember digging into the origins of BarChart positioning with Trace but it was quite complicated. I'll try to work out the source of the exact positions of the elements later, if someone doesn't beat me to it. –  Mr.Wizard Jan 30 at 12:09
1  
Zero bars appears in V9.0.1 in MAC. –  Murta Jan 30 at 12:44
    
@Murta This seems like a bug then. I wonder if caya is using 9.0.0? –  Mr.Wizard Jan 30 at 12:52
    
show 2 more comments

2 Answers

This is what I get using Mathematica version 7:

enter image description here

Probably behavior was changed, but in case it's only an option these are the option values:

Options[BarChart3D]

{AlignmentPoint -> Center, AspectRatio -> Automatic, Axes -> True, AxesEdge -> Automatic, 
 AxesLabel -> None, AxesOrigin -> Automatic, AxesStyle -> {}, Background -> None, 
 BaselinePosition -> Automatic, BaseStyle -> {}, Boxed -> False, BoxRatios -> Automatic, 
 BoxStyle -> {}, ColorOutput -> Automatic, ContentSelectable -> Automatic, 
 ControllerLinking -> Automatic, ControllerMethod -> Automatic, 
 ControllerPath -> Automatic, CoordinatesToolOptions -> Automatic, 
 DisplayFunction :> $DisplayFunction, Epilog -> {}, FaceGrids -> Automatic, 
     FaceGridsStyle -> {}, FormatType :> TraditionalForm, ImageMargins -> 0., 
     ImagePadding -> All, ImageSize -> Automatic, LabelStyle -> {}, Lighting -> "Neutral", 
     Method -> Automatic, PlotLabel -> None, PlotRange -> All, PlotRangePadding -> Automatic, 
     PlotRegion -> Automatic, PreserveImageOptions -> Automatic, Prolog -> {}, 
     RotationAction -> "Fit", SphericalRegion -> False, Ticks -> Automatic, TicksStyle -> {}, 
     ViewAngle -> Automatic, ViewCenter -> Automatic, ViewMatrix -> Automatic, 
     ViewPoint -> Automatic, ViewRange -> All, ViewVector -> Automatic, 
     ViewVertical -> {0, 0, 1}, ChartBaseStyle -> Automatic, ChartStyle -> Automatic, 
     BarOrigin -> Bottom, ChartElements -> Automatic, BarSpacing -> Automatic, 
     ColorFunction -> Automatic, ColorFunctionScaling -> True, ChartLayout -> Automatic, 
     LabelingFunction -> Automatic, ChartElementFunction -> Automatic, ChartLabels -> None, 
     ViewPoint -> Automatic, ChartLegends -> None, PerformanceGoal :> $PerformanceGoal, 
 LegendAppearance -> Automatic}
share|improve this answer
    
Thanks @Mr.Wizard, I have version 9.0.0.0 and it seems behaviour changed. I am happy with my workaround tough. If you can shed light on how to place the labels I will give you the answer; my current manual placing is not portable to other NxM matrices, which is bad. Cheers! –  caya Jan 30 at 22:56
add comment

Thanks all for feedback.

As per zeros not appearing, this is certainly a bug in 9.0.0 Mac. I have upgraded to 9.0.1 and now zeros are displayed.

As per the ticks, the approach was to use ChartLabels along with Placed.

BarChart3D[
 Map[Labeled[#, Text[Style[#, Black, Opacity[1.], Bold, 20]], 
    Above] &, {{1, 0, 2}, {0, 0, 2}, {2, 1, 0}, {0, 2, 1}}, {2}], 
 ChartLayout -> "Grid", BarSpacing -> Large,
 ChartElements -> Graphics3D[Cylinder[]],
 ChartStyle -> Directive[Opacity[0.3]], 
 AxesLabel -> {None, None, None},
 Ticks -> {None, None, {0, 1, 2}},
 ChartLabels -> {Placed[{"Osteo", "Ewing", "Rhabdo", "Neuro"}, Axis], {"Del", "Norm", "Amp"}},
 ViewPoint -> {1.3`, -2.4`, 2.`}]

which produces

Mathematica graphics

Positioning of labels can be improved I imagine (on the Y axis, specially); but I have tried other approaches mentioned in SE here and don't seem to work for 3D graphics.

Using Ticks as I did before placed the labels much better :( although those odd looking positions are still puzzling me.

Could someone improve on this? :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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