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

Szabolcs
  • 24,728
  • 9
  • 85
  • 174
  • Could you upload an image of how it looks for you? [This](http://imgur.com/a/Slbbk) is what I get and it doesn't look cropped to me (unless of course, if I misunderstood what you meant by "cropped") – abcd Jul 02 '11 at 16:15
  • @yoda, see edit. What version do you use? I have 8.0.1 on WinXP. – Szabolcs Jul 02 '11 at 16:26
  • @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. – Szabolcs Jul 02 '11 at 16:29
  • 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. – abcd Jul 02 '11 at 17:11
  • @yoda, I was told it doesn't happen on Linux with 8. It was a mistake to ask about this on SO. – Szabolcs Jul 02 '11 at 17:15

2 Answers2

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

DavidC
  • 3,056
  • 1
  • 20
  • 30
  • 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. – Szabolcs Jul 02 '11 at 16:37
  • 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. – DavidC Jul 02 '11 at 16:47
1

Well, It was not always like that:

enter image description here

Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
  • 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. – Szabolcs Jul 02 '11 at 23:37