lets see the code
import matplotlib.pyplot as pl
fig = pl.figure()
ax = fig.add_axes([0,0,3,2])
langs = ['C', 'C++', 'Java', 'Python', 'PHP']
students = [21,19,28,29,12]
ax.bar(langs,students)
pl.show()
The bar( ) function has width argument to set the width of all bars. It has color argument also, to change the color of bars.
Horizontal bar chart:
CODE:
import matplotlib.pyplot as pl
year=['2007','2008','2009','2010']
p=[97,77,58,92]
c=['b','r','m','g']
pl.barh(year,p,color=c)
pl.xlabel("pass%")
pl.ylabel("year")
pl.show()
OUTPUT
MULTIPLE BAR CHARTS:
CODE:
import numpy as np
import matplotlib.pyplot as plt
data = [[6., 20., 50., 20.],
[4., 23., 48., 18.],
[6., 21., 32., 19.]]
X = np.arange(4)
plt.bar(X + 0.00, data[0], color = 'g', width = 0.25)
plt.bar(X + 0.25, data[1], color = 'b', width = 0.25)
plt.bar(X + 0.50, data[2], color = 'r', width = 0.25)
plt.show()