Wednesday, May 8, 2013

PL#5: Grouped bar and error bars


#!/usr/bin/env python
from __future__ import print_function

import numpy as np
import matplotlib.pyplot as plt

N = 8
barheight1 = (25, 39, 60, 35, 27, 5, 8, 12)
barheight2 = (15, 29, 30, 15, 17, 25, 18, 8)


width = 0.35
ind = np.arange(N) # the x locations
rects1 = plt.bar(ind, barheight1, width = width, color='g')
rects2 = plt.bar(ind+width, barheight2, width = width, color='y')
plt.axis([-0.3, 8, 0, 65])
plt.grid(True)

# other labs
plt.ylabel('Ylab')
plt.title('My plot title')
plt.xticks(ind+width, ('G1', 'G2', 'G3', 'G4', 'G5', 'G6', 'G7', 'G8') )

plt.legend( (rects1[0], rects2[0]), ('CLS1', 'CLS2') )


#!/usr/bin/env python
from __future__ import print_function

import numpy as np
import matplotlib.pyplot as plt

N = 8
barheight1 = (25, 39, 60, 35, 27, 5, 8, 12)
barheight2 = (15, 29, 30, 15, 17, 25, 18, 8)
berr1 = [8]*len(barheight1)
berr2 = [6]*len(barheight2)

width = 0.35
ind = np.arange(N) # the x locations
rects1 = plt.bar(ind, barheight1, width = width, color='g', yerr=berr1, error_kw=dict(elinewidth=2, ecolor='pink'))

rects2 = plt.bar(ind+width, barheight2, width = width, color='y', yerr=berr2, error_kw=dict(elinewidth=2, ecolor='pink'))
plt.axis([-0.3, 8, 0, 65])
plt.grid(True)

# other labs
plt.ylabel('Ylab')
plt.title('My plot title')
plt.xticks(ind+width, ('G1', 'G2', 'G3', 'G4', 'G5', 'G6', 'G7', 'G8') )

plt.legend( (rects1[0], rects2[0]), ('CLS1', 'CLS2') )








No comments:

Post a Comment