barchart: center xticklabels for only one data set

Hello,
I tried to modify the bar chart demo for my case.
I want to plot only bar charts for one data set.

But the xticklables are not centered below the bars, rather are they left in
place as if there were still two data sets.

How do I modify set_xticklabels in oder to get the lables centered below the bar
one data set?

Thanks in advance,
Timmie

#### modified bar charts demo

#!/usr/bin/env python
# a bar plot with errorbars
import numpy as np
import matplotlib.pyplot as plt

N = 5
menMeans = (20, 35, 30, 35, 27)
menStd = (2, 3, 4, 1, 2)

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

fig = plt.figure()
ax = fig.add_subplot(111)
rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd)

womenMeans = (25, 32, 34, 20, 25)
womenStd = (3, 5, 2, 3, 3)
#~ rects2 = ax.bar(ind+width, womenMeans, width, color='y', yerr=womenStd)

# add some
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind+width)
ax.set_xticklabels( ('G1', 'G2', 'G3', 'G4', 'G5'), multialignment='left',
position=(-2,0) )

#~ ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') )

def autolabel(rects):
    # attach some text labels
    for rect in rects:
        #~ print rect
        height = rect.get_height()
        print height
        ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height),
                ha='center', va='bottom')
                
autolabel(rects1)
#~ autolabel(rects2)

plt.show()

http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.bar

use

ax.set_xticks(ind+width*.5)

instead of

ax.set_xticks(ind+width)

-JJ

···

On Thu, Mar 5, 2009 at 1:40 PM, Timmie <timmichelsen@...1423...> wrote:

Hello,
I tried to modify the bar chart demo for my case.
I want to plot only bar charts for one data set.

But the xticklables are not centered below the bars, rather are they left in
place as if there were still two data sets.

How do I modify set_xticklabels in oder to get the lables centered below the bar
one data set?

Thanks in advance,
Timmie

#### modified bar charts demo

#!/usr/bin/env python
# a bar plot with errorbars
import numpy as np
import matplotlib.pyplot as plt

N = 5
menMeans = (20, 35, 30, 35, 27)
menStd = (2, 3, 4, 1, 2)

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

fig = plt.figure()
ax = fig.add_subplot(111)
rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd)

womenMeans = (25, 32, 34, 20, 25)
womenStd = (3, 5, 2, 3, 3)
#~ rects2 = ax.bar(ind+width, womenMeans, width, color='y', yerr=womenStd)

# add some
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind+width)
ax.set_xticklabels( ('G1', 'G2', 'G3', 'G4', 'G5'), multialignment='left',
position=(-2,0) )

#~ ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') )

def autolabel(rects):
# attach some text labels
for rect in rects:
#~ print rect
height = rect.get_height()
print height
ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height),
ha='center', va='bottom')

autolabel(rects1)
#~ autolabel(rects2)

plt.show()

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users