4
$\begingroup$

The grid lines in the following plot extend beyond the data and, in particular, into the numbers along the axis.

BarChart[{{1,2,3},{3,1,2}},BarSpacing->{0,2}]
Show[%,GridLines->{None,Range[3]}]

enter image description here

Question

Why does this happen? What can be done to keep the grid lines from going left of the vertical axis?

$\endgroup$
1
  • 1
    $\begingroup$ Try PlotRangePadding->None. $\endgroup$
    – Verbeia
    Commented Oct 31, 2014 at 6:34

2 Answers 2

7
$\begingroup$

Essentially the Axis is in the wrong place. A more dramatic example:

BarChart[{{1, 2, 3}, {3, 1, 2}},
 BarSpacing -> {0, 2},
 GridLines -> {None, Range[3]}, 
 AxesOrigin -> {3, 0}
]

enter image description here

You can correct this with PlotRangePadding -> 0 (as already proposed) or you can use a Frame instead:

BarChart[{{1, 2, 3}, {3, 1, 2}},
 BarSpacing -> {0, 2},
 GridLines -> {None, Range[3]}, 
 Frame -> Left
]

enter image description here

$\endgroup$
3
  • $\begingroup$ Yes, both solutions work for the example I gave, but this one continues to work after adding the option PlotRange -> {0, 4}) but the other solution no longer works. $\endgroup$ Commented Oct 31, 2014 at 7:08
  • $\begingroup$ @Mr.Wizard nice explaination so +1 :D $\endgroup$
    – Junho Lee
    Commented Oct 31, 2014 at 7:26
  • $\begingroup$ @JunhoLee Thank you. I also voted for your answer. $\endgroup$
    – Mr.Wizard
    Commented Oct 31, 2014 at 7:26
2
$\begingroup$

You can use PlotRangePadding->None as Option of Graphics.

BarChart[{{1, 2, 3}, {3, 1, 2}}, BarSpacing -> {0, 2}, 
 GridLines -> {None, Range[3]}, PlotRangePadding -> None]

enter image description here

version 8 makes the same result @Mr.Wizard 's comment as Range[0, 3]

BarChart[{{1, 2, 3}, {3, 1, 2}}, BarSpacing -> {0, 2}, 
 GridLines -> {None, Range[0, 3]}, Frame -> Left]

enter image description here

$\endgroup$
4
  • $\begingroup$ I don't think this answers the question $\endgroup$
    – Verbeia
    Commented Oct 31, 2014 at 6:42
  • $\begingroup$ @Verbeia I made misunderstand and corrected. thanks again. :) $\endgroup$
    – Junho Lee
    Commented Oct 31, 2014 at 6:54
  • $\begingroup$ For version 8 change Range[3] to Range[0, 3]. :-) $\endgroup$
    – Mr.Wizard
    Commented Oct 31, 2014 at 7:22
  • $\begingroup$ @Mr.Wizard thanks a lot. $\endgroup$
    – Junho Lee
    Commented Oct 31, 2014 at 7:23

Your Answer

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

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