4
$\begingroup$

I have a BarChart (Mathematica 9.0.1)

BarChart[{1, 2, 3},
ChartLabels -> (Rotate[Text[Style[#, FontSize -> Scaled[0.05]]], -Pi/2]
& /@{abcdabcd,abcdabcd, abcdabcd})]

enter image description here

and would like to add a vertical label to the y-axis. I tried

BarChart[{1, 2, 3},
ChartLabels -> (Rotate[Text[Style[#, FontSize -> Scaled[0.05]]], -Pi/2]
& /@ {abcdabcd, abcdabcd, abcdabcd}),
FrameLabel -> {None, "y-axis"},
Frame -> {False, True, False, False}]

and it's perfect except for a gap between the two axes (which is somehow extremely ugly with the actual data):

enter image description here

I tried using Labeled, but then the label is positioned too low (i want it at the center of the y-axis):

Labeled[BarChart[{1, 2, 3},
ChartLabels -> (Rotate[Text[Style[#, FontSize -> Scaled[0.05]]], -Pi/2]
& /@ {abcdabcd, abcdabcd, abcdabcd})],
{Rotate[Style["y-axis", FontFamily -> "Helvetica"], Pi/2]}, {Left}]

(Can't post > 2 links)

Any help would be most appreciated!

$\endgroup$
4
  • $\begingroup$ Welcome, Stefan. I embedded the images for you. The image/link limitation is an anti-spam measure that will be lifted once you start using the site more. $\endgroup$
    – Mr.Wizard
    May 18, 2013 at 14:07
  • $\begingroup$ @Silvia: If I try that, the gap is gone, but so is the label ('y-axis'). $\endgroup$
    – Stefan Ca
    May 18, 2013 at 17:24
  • $\begingroup$ Oops, you're right. Sorry for my oversight.. $\endgroup$
    – Silvia
    May 18, 2013 at 17:42
  • $\begingroup$ Related: (18807), (19893) $\endgroup$
    – Mr.Wizard
    Mar 7, 2017 at 6:48

2 Answers 2

1
$\begingroup$

In your second attempt (which results in the gap), you can remove the gap by eliminating the PlotRangePadding for the x-axis.

PlotRangePadding -> {0, 0}
$\endgroup$
2
  • $\begingroup$ You're right, that's even a bit simpler than Mr. Wizards solution. $\endgroup$
    – Stefan Ca
    May 18, 2013 at 17:28
  • $\begingroup$ @Stefan For what it's worth the output (from this) looks a bit different on version 7, and the longer code was required to match your output. Also, I believe you should be able to use the slightly shorter PlotRangePadding -> 0 to produce the same output as given by PlotRangePadding -> {0, 0}. $\endgroup$
    – Mr.Wizard
    May 19, 2013 at 5:52
1
$\begingroup$

This feels a lot more complicated than it should be, but I think at least it works:

BarChart[{1, 2, 3},
 ChartLabels ->
  (Rotate[Text[Style[#, FontSize -> Scaled[0.05]]], -Pi/2] & /@ {abcdabcd, abcdabcd, abcdabcd}),
 FrameLabel -> {None, "y-axis"},
 Frame -> {1, 1, 0, 0},
 FrameTicks -> {None, All},
 PlotRangePadding -> {0.1, 0}
]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you very much! It's exactly what a needed. $\endgroup$
    – Stefan Ca
    May 18, 2013 at 14:41

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.