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 test BarChart is generated by the code that follows it:

enter image description here

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

BarChart[MapThread[Labeled[#1, #2, Above] &, {data, {1, 2, 3}}], 
 ChartLayout -> "Stacked", 
 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"}, 
 BaseStyle -> {FontFamily -> "Helvetica", FontSize -> 14}]

Since only a y-axis component of Frame is rendered: Frame -> {False, True, False, False} the "x axis" label of FrameLabel -> {"x axis", "y axis"} is omitted - and that's consistent with documentation.

Is it possible to display "x axis" at the location it would be if the bottom component of the Frame were there and preserving the set BaseStyle values (eg Font, FontSize)?

This can be done using Inset but positioning is ad-hoc and it does not preserve BaseStyle values.

Wrapping Labeled around Barchart doesn't correctly center the text and moreover does not use the BaseStyle values, as the following screenshot shows. Here for comparison the bottom component of Frame is True - and note the disastrous clash of graphical elements.

enter image description here

Finally, using the bottom Frame component: Frame -> {True, True, False, False} but without ticks: FrameTicks -> {None, Automatic, None, None} results in an ugly double axis and overlap in labels:

enter image description here

Any other options, eg using LabelingFunction?

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

You can remove the overlaid ticks by using FrameTicksStyle to set them to Transparent and remove the doubled edge by setting PlotRangePadding to None, like so:

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

Or you could explicitly set the FrameTicks to something invisible but that takes up the same vertical spacing you want, like so:

BarChart[MapThread[Labeled[#1, #2, Above] &, {data, {1, 2, 3}}], 
 ChartLayout -> "Stacked", 
 ChartStyle -> 
  Reverse@{Lighter@Blue, Blue, Darker@Blue, Darker@Darker@Blue}, 
 ChartLabels -> {{"a", "b", "c"}, None}, 
 Frame -> {True, True, False, False}, 
 FrameTicks -> {{Automatic, Automatic}, {{{1, ""}}, None}}, 
 PlotRangePadding -> None, FrameLabel -> {"x axis", "y axis"}, 
 BaseStyle -> {FontFamily -> "Helvetica", FontSize -> 14}]
share|improve this answer
    
Thanks Xerxes, that works. –  alancalvitti Feb 20 '13 at 21:38
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.