Reputation: 379
I am trying to reproduce this chart embedded in a PyQt GUI but there is a problem with what my code
N = 5
menMeans = (20, 35, 30, 35, 27)
womenMeans = (25, 32, 34, 20, 25)
menStd = (2, 3, 4, 1, 2)
womenStd = (3, 5, 2, 3, 3)
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars: can also be len(x) sequence
p1 = self.axes.bar(ind, menMeans, width, color='#d62728', yerr=menStd)
p2 = self.axes.bar(ind, womenMeans, width,
bottom=menMeans, yerr=womenStd)
self.axes.set_ylabel('Scores')
self.axes.set_title('Scores by group and gender')
self.axes.set_xticks(ind)
self.axes.set_xticklabels(['G1', 'G2', 'G3', 'G4', 'G5'])
self.axes.set_yticklabels(np.arange(0, 81, 10))
self.axes.legend((p1[0], p2[0]), ('Men', 'Women'))
produces.
G1 should not be exactly at the origin but a little along. What needs to be changed to do this?
Upvotes: 0
Views: 1613
Reputation: 339380
The example you link to is for matplotlib version 2.0. However you are running 1.5 or below. So you need to refer to the example of the previous versions: bar_stacked example for 1.5. Alternatively, you can update matplotlib to version 2.0.
The alternative would be to use the align
argument to bar
plt.bar(... , align="center")
Upvotes: 1