Not cropping BarChart when using Frame instead of Axes
Asked Answered
E

2

2

I just found out that a BarChart may get cropped when using Frame rather than Axes.

Example:

data = {.2, .4, .6, 0., 0., 0.}
BarChart[data]
BarChart[data, Frame -> True, Axes -> False]

Is this a feature or a bug? If it is a feature, is there an easy way to prevent cropping?

EDIT

Screenshot, per request:

enter image description here

Embargo answered 2/7, 2011 at 15:30 Comment(5)
Could you upload an image of how it looks for you? This is what I get and it doesn't look cropped to me (unless of course, if I misunderstood what you meant by "cropped")Houselights
@yoda, see edit. What version do you use? I have 8.0.1 on WinXP.Embargo
@yoda, in general, BarChart does not seem to support frames, only axes. E.g. ticks are wrong with frames. It's a pity because occasionally it's good to have a visible frame.Embargo
I use v7 on a Mac OSX 10.6. I think some additional functionality was added to the histogram/barchart class of functions (e.g., getting hist counts without having to manually reap and sow, etc) in v8 and this might be a bug introduced then.Houselights
@yoda, I was told it doesn't happen on Linux with 8. It was a mistake to ask about this on SO.Embargo
D
1

How about using PlotRange?...

data = {.2, .4, .6, 0., 0., 0.}
BarChart[data]
BarChart[data, Frame -> True, Axes -> False, 
PlotRange -> {{.5, 6.5}, {0, .7}}, 
FrameTicks -> {None, Automatic, None, None}]

Figure


Edit

I'm beginning to think it is indeed a bug. Look what happens if we simply change the order of the elements in data. It acknowledges (but does not display the baseline of) the bars of zero height that it previously ignored. Notice that I didn't have to tweak the display using PlotRange this time around.

Bar2

Defroster answered 2/7, 2011 at 16:29 Comment(2)
Of course that works, but that amounts to me having to compute the appropriate PlotRange from the Length of the list, which is quite cumbersome. I'm getting the feeling that this is either a bug, or BarChart simply wasn't made to work with frames at all.Embargo
Perhaps it was an aesthetic choice. There are quite a few examples in the documentation that employ fat, stubby bars when only three appear, but thick bars when 5 or more appear. For instance BarChart[{1, Style[2, Yellow], 3}, ChartStyle -> {Red, Green, Blue}] is proudly displayed directly under the example of BarChart[{{1, 2, 3}, {4, 5, 6}}, ChartStyle -> {{Yellow, Magenta}, {Red, Green, Blue}}]. And there are so many options, it seems WR didn't leave much to chance.Defroster
V
1

Well, It was not always like that:

enter image description here

Vertical answered 2/7, 2011 at 18:56 Comment(1)
Apparently it's machine-dependent (not version-dependent). Note in David's answer below that the zero-height bars are not visible at all (same here), while in your screenshot they are. Must be some rounding-related numerical artefact.Embargo

© 2022 - 2024 — McMap. All rights reserved.