2
$\begingroup$

Creating a BarChart with {1, 2, 3, 0} as

BarChart[{1, 2, 3, 0}, Axes -> False, Frame -> True]

gives me only the first three bars, a chart identical to just

BarChart[{1, 2, 3}, Axes -> False, Frame -> True]
  1. Is this an intended behaviour or a bug?

  2. (Originally I asked for a workaround. I think I can just use Axes instead of Frame. Let me ask this instead for the sake of knowledge.) What to do if I need Frame but not Axes?

I'm using Mathematica 9.

$\endgroup$
2
  • $\begingroup$ is that cheating? BarChart[{1, 2, 3, 0}, AxesStyle -> Directive[Opacity[0]], Frame -> True]. There must be a smarter way - $\endgroup$ Apr 4, 2013 at 11:23
  • $\begingroup$ Your workaround is great. I think you have answered Question 2! Could you please post it as an answer so I can mark the question as solved? $\endgroup$
    – Taiki
    Apr 4, 2013 at 12:45

3 Answers 3

2
$\begingroup$

I cannot answer why this is happening. Intuitively, I interpret BarChart as a chart with no "real", scaled, x-axis. Thus, a frame does not really make a lot of sense to me (with ticks)...

Nevertheless, you could use the following work-around to make the axis "vanish":

BarChart[{1, 2, 3, 0}, AxesStyle -> Directive[Opacity[0]], Frame -> True]

This will keep the last (zero) bar:

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you for your idea. Now I'll just customise the chart further, like this. $\endgroup$
    – Taiki
    Apr 4, 2013 at 15:05
2
$\begingroup$

Are you sure it's not there? I get this picture:

enter image description here

What appears to be nothingness attached on the end is really a bar of height zero. You can see this more clearly if you do it in 3D

BarChart3D[{1, 2, 3, 0}]

which gives

enter image description here

Now you can see the stump of the zero bar. Another way to see it would be:

BarChart[{1, 2, 3, 0}, LabelingFunction -> (Placed[#, Above] &)]

enter image description here

which labels things with the number.

$\endgroup$
1
  • $\begingroup$ Thank you. I just updated my question a bit. It seems the option Axes -> False causes the last zero to disappear. $\endgroup$
    – Taiki
    Apr 4, 2013 at 10:26
0
$\begingroup$

Perhaps you could do:

GraphicsRow[BarChart[#, AxesOrigin -> {0, -1}] & /@ {{1, 2, 3, 0}, {1, 2, 3}}]

Mathematica graphics

Just to be sure

$\endgroup$
1
  • $\begingroup$ Thank you. Now I have updated my question. With Axes set to False, the last zero really disappears. $\endgroup$
    – Taiki
    Apr 4, 2013 at 10:39

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.