Newbie: How to control space between sets of bars in bar chart

My apologies in advance if this is obvious.

I have a bar chart with three sets of figures and I would like some space between the three sets. I cannot seem to find anything in the manual or online which explains how to separate sets of data.
I tried adding a blank (white bar) with 0 data and that did not work. When I made the data non zero I got overlapping bars. Basically I want the US/EU/Japan data slightly set apart. This is the default if I use a speadsheet package.

I must be doing something obviously wrong.

Thank you in advance for your help
Christopher

···

----------------
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt

N = 3
_1971 = (120, 130, 70)
_2008 = (400, 370, 180)
_2011 = (350, 350, 140)
# _blank = (100,100,100)

ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars

plt.subplot(111)
rects1 = plt.bar(ind, _1971, width, color='r')
rects2 = plt.bar(ind+width, _2008, width, color='y')
rects3 = plt.bar(ind+width+width, _2011, width, color='b')
# rects4 = plt.bar(ind+width+width+width, _blank, width, color='w')

plt.ylabel('Annual Expenditure ($bn)')
plt.title('Net Imports')
plt.xticks((ind+(width*1.5)), ('US', 'EU', 'Japan'))
plt.axes().yaxis.grid(True, linestyle='--', which='major', color='grey',
        alpha=0.75) # add a grid to the subplot

plt.show()
# plt.savefig('oilbar.pdf')

----------------

Are you looking for something that is grouped in threes (3 US bars, space, 3 EU bars, space, 3 Japan bars)? Or what? It would be helpful if you include an example of what you would like from the spreadsheet program.

Btw, if you want space in between the three groups like I described above, you can simply make the ‘width’ variable smaller (like 0.15).

Ben Root

···

On Wed, Jan 12, 2011 at 6:27 PM, Christopher Brewster <cbrewster@…287…> wrote:

My apologies in advance if this is obvious.

I have a bar chart with three sets of figures and I would like some space between the three sets. I cannot seem to find anything in the manual or online which explains how to separate sets of data.

I tried adding a blank (white bar) with 0 data and that did not work. When I made the data non zero I got overlapping bars. Basically I want the US/EU/Japan data slightly set apart. This is the default if I use a speadsheet package.

I must be doing something obviously wrong.

Thank you in advance for your help

Christopher


#!/usr/bin/env python

import numpy as np

import matplotlib.pyplot as plt

N = 3

_1971 = (120, 130, 70)

_2008 = (400, 370, 180)

_2011 = (350, 350, 140)

_blank = (100,100,100)

ind = np.arange(N) # the x locations for the groups

width = 0.35 # the width of the bars

plt.subplot(111)

rects1 = plt.bar(ind, _1971, width, color=‘r’)

rects2 = plt.bar(ind+width, _2008, width, color=‘y’)

rects3 = plt.bar(ind+width+width, _2011, width, color=‘b’)

rects4 = plt.bar(ind+width+width+width, _blank, width, color=‘w’)

plt.ylabel(‘Annual Expenditure ($bn)’)

plt.title(‘Net Imports’)

plt.xticks((ind+(width*1.5)), (‘US’, ‘EU’, ‘Japan’))

plt.axes().yaxis.grid(True, linestyle=‘–’, which=‘major’, color=‘grey’,

    alpha=0.75)          # add a grid to the subplot

plt.show()

plt.savefig(‘oilbar.pdf’)


Christopher Brewster, on 2011-01-13 00:27, wrote:

I have a bar chart with three sets of figures and I would like
some space between the three sets. I cannot seem to find
anything in the manual or online which explains how to separate
sets of data. I tried adding a blank (white bar) with 0 data
and that did not work. When I made the data non zero I got
overlapping bars. Basically I want the US/EU/Japan data
slightly set apart. This is the default if I use a speadsheet
package.

Hi Christopher,

Given the width for each bar that you've chosen and how you're
offsetting each year, there's just not room left between the
indexes that you're using. Just change your ind assignment line
to this:

ind = np.arange(0, 2*N, 2)

this spaces your indexes out more.

hope that helps,

···

--
Paul Ivanov
314 address only used for lists, off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7