Notes 55 Creating Bar Graph
Notes 55 Creating Bar Graph
import matplotlib.pyplot as pl
a=[1,2,3,4,5]
b=[10,25,16,70,45]
pl.bar(a,b)
Example2:
import matplotlib.pyplot as pl
a=[1,2,3,4,5]
b=[10,25,16,70,45]
pl.bar(a,b, color=['r','g','b','y','c'])
import matplotlib.pyplot as pl
import numpy as np
a=np.arange(5)
b=[10,25,16,70,45]
c=[5,10,12,60,35]
pl.bar(a,b, color='g',width=.25)
pl.bar(a+.25,c,color='r',width=.25)
Steps:
1) Decide number of X points
2) Decide Thickness of each bar
3) Give different color to different data range
4) Width argument remains the same for all ranges being plotted
5) Plot using bar() for each range separately.
Important:
If you will not take care of X points and width of each bar, then the chart will be
created as follows:
import matplotlib.pyplot as pl
import numpy as np
a=np.arange(5)
b=[10,25,16,70,45]
c=[5,10,12,60,35]
pl.bar(a,b, color='g',width=.5)
pl.bar(a,c,color='r',width=.25)
import matplotlib.pyplot as pl
import numpy as np
a=np.arange(5)
b=[10,25,16,70,45]
c=[5,10,12,60,35]
pl.bar(a,b, color='g',width=.25)
pl.bar(a,c,color='r',width=.25)