2
$\begingroup$

Is there some way to stop the y-axis plotting below the origin in the chart below. The PlotRangePadding is required to make room for the labels, but it pulls the y-axis too low, (as indicated). The axis graphics don't seem to be editable.

data = {{3, 2}, {6, 3}, {8, 10}, {9, 9},
   {3, 1}, {5, 2}, {6, 4}, {7, 8},
   {4, 1}, {7, 2}, {9, 0}, {10, 12}};

bc = BarChart[data, BarSpacing -> {0, 1}, PerformanceGoal -> "Speed",
   ChartStyle -> {LightOrange, LightGreen}, ImageSize -> 900, AspectRatio -> 0.4,
   ChartLabels -> {Flatten@ConstantArray[{"Mar", "Jun", "Sep", "Dec"}, 3], None},
   ImagePadding -> 8, PlotRangePadding -> {Automatic, {2, Automatic}}];

labels = MapThread[Inset[Style[#1, Bold, 16], {#2, -1.8}, {Center, Bottom}] &,
   {{"2015", "2016", "2017"}, {6.5, 18.5, 30.5}}];

selopts = {AspectRatio, Axes, AxesOrigin, ImageSize, PlotRangePadding};
opts0 = selopts /. bc[[2]];
opts = Thread[selopts -> opts0];
Graphics[bc[[1]], opts, Epilog -> Append[labels,
   Inset[SwatchLegend[{LightOrange, LightGreen}, Style[#, 12] & /@ {"Masha", "Bear"},
     LegendMarkerSize -> 20, LegendFunction -> (Framed[#, RoundingRadius -> 4,
         FrameStyle -> Gray] &)], {28, 10.5}]]]

enter image description here

$\endgroup$
3
  • 2
    $\begingroup$ You asked for that with PlotRangePadding. $\endgroup$
    – Alan
    Mar 23, 2018 at 15:30
  • $\begingroup$ @Alan - Yes, if PlotRangePadding -> {Automatic, {0, Automatic} is used it fixes the y-axis but chops off the year labels. I might have to use Labeled for the year labels but then they are disconnected from the chart. Not too bad if the chart width is constant though. $\endgroup$ Mar 23, 2018 at 16:25
  • $\begingroup$ Loosely related question: PlotRange adjustments with BarChart $\endgroup$ Mar 23, 2018 at 16:29

1 Answer 1

3
$\begingroup$

Adding the options PlotRangePadding -> Automatic and ImagePadding -> {{8, 8}, {50, 8}} before opts in Graphics gives

enter image description here

$\endgroup$
1
  • $\begingroup$ Terrific, thanks. $\endgroup$ Mar 24, 2018 at 8:20

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.