2
$\begingroup$

Bug introduced in 9.0 and 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.

$\endgroup$
7
  • $\begingroup$ Please, what version are you using? This is apparently version specific. $\endgroup$
    – Mr.Wizard
    Jan 30, 2014 at 12:00
  • $\begingroup$ 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. $\endgroup$
    – Mr.Wizard
    Jan 30, 2014 at 12:09
  • 1
    $\begingroup$ Zero bars appears in V9.0.1 in MAC. $\endgroup$
    – Murta
    Jan 30, 2014 at 12:44
  • $\begingroup$ @Murta This seems like a bug then. I wonder if caya is using 9.0.0? $\endgroup$
    – Mr.Wizard
    Jan 30, 2014 at 12:52
  • $\begingroup$ Possibly related: BarChart without axes neglects the last zero of a list $\endgroup$
    – Mr.Wizard
    Jan 30, 2014 at 12:53

2 Answers 2

1
$\begingroup$

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}
$\endgroup$
1
  • $\begingroup$ 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! $\endgroup$
    – carlosayam
    Jan 30, 2014 at 22:56
0
$\begingroup$

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? :)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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