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.

This bug was fixed in version 10.0.0


When BarChart layout is "Stacked", setting BarOrigin -> Top makes the y-axis tick marks negative. BarChart documentation shows an example - but not "Stacked" - with correct positive y-axis tick marks.

For example,

data = Table[RandomInteger[{1, 10}], {3}, {4}];

BarChart[MapThread[Labeled[#1, #2, Above] &, {data, {1, 2, 3}}], 
 ChartLayout -> "Stacked",
 BarOrigin -> Top, 
 ChartStyle -> 
  Reverse@{Lighter@Blue, Blue, Darker@Blue, Darker@Darker@Blue}, 
 ChartLabels -> {{"a", "b", "c"}, None}, 
 Frame -> {False, True, False, False}, 
 FrameLabel -> {"x axis", "y axis"},
 FrameTicks -> {None, Automatic}, 
 BaseStyle -> {FontFamily -> "Helvetica", FontSize -> 14}]

Gives:

enter image description here

Is there an option to control this behavior without explicitly setting FrameTicks -> {None, Table[{-i, i}, {i, 0, 25, 5}]}, which works but is a hack.

share|improve this question
    
The ticks are positive if without the Frame -> {False, True, False, False} option. I guess this setting overrides the internal procedure of BarChart? –  Silvia Feb 25 '13 at 19:17
    
I would say this is a bug and should probably be reported. –  s0rce Feb 25 '13 at 19:59

3 Answers 3

up vote 8 down vote accepted

By looking at the InputForm of the graphics in original post, I found a function Charting`FindTicks. It looks like what's needed.

Change FrameTicks -> {None, Automatic} to FrameTicks -> {None, Charting`FindTicks[{-1, 0}, {1, 0}]}:

Mathematica graphics

share|improve this answer
    
Where did the x-axis frame label go? I can't seem to find it even if I adjust the PlotRangePadding –  s0rce Feb 25 '13 at 20:00
1  
@s0rce Because OP sets Frame -> {False, True, False, False}. Try Frame -> {False, True, True, False}, FrameLabel -> {{"y axis", None}, {None, "x axis"}} etc. –  Silvia Feb 25 '13 at 20:05
    
+1 looks like you can also rescale ticks that way ChartingFindTicks[{1, 0}, {0.5, 0}]` –  Mike Honeychurch Feb 25 '13 at 22:59
    
@MikeHoneychurch It seems charts functions use a lot of special methods internally. Have seen many of them when tracing BarChart. –  Silvia Feb 26 '13 at 5:16
    
Yes I've used Trace on Barcharts before but the output was so large I didn't bother trying to figure it out! –  Mike Honeychurch Feb 26 '13 at 5:21

This seems like a bug in BarChart in that the non-negative ticks are not applied to the Frame.
One can fix this by applying the frame afterward and porting the Ticks spec:

BarChart[MapThread[Labeled[#1, #2, Above] &, {data, {1, 2, 3}}], BarOrigin -> Top, 
  ChartLayout -> "Stacked", 
  ChartStyle -> Reverse@{Lighter@Blue, Blue, Darker@Blue, Darker@Darker@Blue}, 
  ChartLabels -> {{"a", "b", "c"}, None}, FrameLabel -> {"x axis", "y axis"}];

Show[%, Frame -> {0, 1, 0, 0}, FrameTicks -> Options[%, Ticks][[1, 2]]]

Mathematica graphics

Examination of the content of that option reveals the Charting`FindTicks function that Silvia posted, which is a more direct way in this case. This answer however may illustrate a way of approaching other such problems which appear from time to time.

share|improve this answer

One possible, although probably not ideal solution is to remove the Frame. Since you are not using most of the Frame anyways this mostly changes where the Labels are put.

data = Table[RandomInteger[{1, 10}], {3}, {4}];

BarChart[MapThread[Labeled[#1, #2, Above] &, {data, {1, 2, 3}}], 
 ChartLayout -> "Stacked", BarOrigin -> Top, 
 ChartStyle -> 
  Reverse@{Lighter@Blue, Blue, Darker@Blue, Darker@Darker@Blue}, 
 ChartLabels -> {{"a", "b", "c"}, None}, Frame -> False, 
 AxesLabel -> {"x axis", "y axis"}, FrameTicks -> {None, Automatic}, 
 BaseStyle -> {FontFamily -> "Helvetica", FontSize -> 14}]

Mathematica graphic

share|improve this answer

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.