Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Clen bar plot demo
  • Loading branch information
gabraganca committed Jun 29, 2013
commit b0f85e7373d7c580cd1e6e8492abd1f3a726a0e7
40 changes: 7 additions & 33 deletions examples/api/barchart_demo.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,13 @@

#!/usr/bin/env python
# a bar plot with errorbars
import numpy as np
"""
Demo of multiple bar plots.
"""
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, ax = plt.subplots()
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 text for labels, title and axes ticks
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') )

ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') )
values = (20, 35, 30, 35, 27)
pos = (0, 1, 2, 3, 4)

def autolabel(rects):
# attach some text labels
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height),
ha='center', va='bottom')
plt.bar(left=pos, height=values, width=0.5, color='r')

autolabel(rects1)
autolabel(rects2)
plt.title('Example of bar plots')

plt.show()