Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bar chart ticks not placed well?

98 views
Skip to first unread message

rs_poetic

unread,
Dec 31, 2009, 3:19:12 AM12/31/09
to
Hello,
in this simple bar chart, there are 101 bars (some of them very small
and including 0 and 100). The x axis labels appear to be shifted a bit
to the left. The apparent misplacement is enough to be noticed and to
confuse the reader. Am I using the wrong command, or....?

s = Sum[Binomial[100, k], {k, 0, 100}];
slist = Table[Binomial[100, k], {k, 0, 100}];
labellist = Table[k, {k, 0, 100, 25}];
BarChart[N[slist/s], Ticks -> {labellist, Automatic}]

Bob Hanlon

unread,
Jan 1, 2010, 5:37:14 AM1/1/10
to

First, the BarSpacing must be set to zero. Then there must be a slight shift of 1/2 to put the ticks in the middle of the bars. This latter issue is more evident for small n (look also at n=10).

n = 100;

s = 2^n;

slist = Table[Binomial[n, k]/s,
{k, 0, n}];

Total[slist]

1

Show[{BarChart[slist,
Ticks -> {
Table[{k + 1/2, k}, {k, n/10, n, n/10}],
Automatic},
BarSpacing -> 0,
ImageSize -> 400],
Plot[Interpolation[
Thread[{Range[0, n], slist}]][x - 1/2],
{x, 1/2, n + 1/2},
PlotRange -> All,
PlotStyle -> Directive[Red, Thick]]}]


Bob Hanlon

---- rs_poetic <schantz...@cox.net> wrote:

=============

dh

unread,
Jan 1, 2010, 5:38:48 AM1/1/10
to
Hi,
Ticks can not be used with BarChart because they refer to coordinates
of the whoe Plot not to bars.
Here is a workaround where we put corresponding labels below the bars:

s = Sum[Binomial[100, k], {k, 0, 100}];
slist = Table[Binomial[100, k], {k, 0, 100}];
labellist = Table[k, {k, 0, 100, 25}];

i = 0;
BarChart[N[slist/s],
LabelingFunction -> (If[Mod[++i, 25] == 0, Placed[i, Below], ""] &)]

Daniel

r_poetic

unread,
Jan 5, 2010, 1:46:00 AM1/5/10
to
On Jan 1, 5:37 am, Bob Hanlon <hanl...@cox.net> wrote:
> First, the BarSpacing must be set to zero. Then there must be a slight shift of 1/2 to put the ticks in the middle of the bars. This latter issue is more evident for small n (look also at n=10).
>
> n = 100;
>
> s = 2^n;
>
> slist = Table[Binomial[n, k]/s,
> {k, 0, n}];
>
> Total[slist]
>
> 1
>
> Show[{BarChart[slist,
> Ticks -> {
> Table[{k + 1/2, k}, {k, n/10, n, n/10}],
> Automatic},
> BarSpacing -> 0,
> ImageSize -> 400],
> Plot[Interpolation[
> Thread[{Range[0, n], slist}]][x - 1/2],
> {x, 1/2, n + 1/2},
> PlotRange -> All,
> PlotStyle -> Directive[Red, Thick]]}]
>
> Bob Hanlon
>
> ---- rs_poetic <schantz-pla...@cox.net> wrote:
>
> =============
> Hello,
> in this simple bar chart, there are 101 bars (some of them very small
> and including 0 and 100). The x axis labels appear to be shifted a bit
> to the left. The apparent misplacement is enough to be noticed and to
> confuse the reader. Am I using the wrong command, or....?
>
> s = Sum[Binomial[100, k], {k, 0, 100}];
> slist = Table[Binomial[100, k], {k, 0, 100}];
> labellist = Table[k, {k, 0, 100, 25}];BarChart[N[slist/s], Ticks -> {labellist, Automatic}]

Thanks! I appreciate both solution and the extra material about
interpolation.
RS

0 new messages