Program5
BCS358D
Histogram Plot using Matplotlib
Write a Python program to Demonstrate how to Draw a Histogram Plot using
Matplotlib.
# case 1)
import [Link] as plt
#%matplotlib inline
age_men = [25,11,68,18,27,28,15,43,58,63,43,65,51,36,33,26,23,35,49,58]
[Link](age_men, bins=6)
[Link]()
# case 2)
bins =[10,20,30,40,50,60,70]
[Link](age_men, bins=bins, edgecolor='r', )
[Link]()
# case 3)
from matplotlib import style
[Link]('fivethirtyeight') #bmh , fivethirtyeight, ggplot
[Link](age_men, bins=10,
edgecolor='y', color='g', rwidth=0.7)
[Link]('Age of people', fontsize=20)
[Link]('Number of people', fontsize=20)
[Link]('Age vs number of people', fontsize=20)
[Link]()
# case 4)
age_men = [25,11,68,18,27,28,15,43,58,63,43,65,51,36,33,26,23,35,49,58]
age_women = [48,57,59,25,19,37,18,56,22,25,56,25,14,49,53,45,46,19,28,70, 31]
[Link](figsize=(6,6))
[Link]('ggplot')
bins =[10,20,30,40,50,60,70]
[Link]([age_men, age_women], bins=bins, color=['blue', 'orange'],rwidth=0.5, label=['men', 'women'])
[Link]('Age of people', fontsize=20)
[Link]('Number of people', fontsize=20)
[Link]('Age vs number of people', fontsize=20)
[Link](loc='upper right')
[Link]()
Pie Chart using Matplotlib
Write a Python program to Demonstrate how to Draw a Pie Chart using Matplotlib.
#%matplotlib inline
import [Link] as plt
exp_vals = [1400,600,300,410,250]
exp_labels = ["Home Rent","Food","Phone/Internet Bill","Car ","Other Utilities"]
[Link](exp_vals,labels=exp_labels, shadow=True)
[Link]()
# pie chart with perfect circle
[Link](exp_vals,labels=exp_labels, shadow=True,
autopct='%0.1f%%',radius=1.5)
[Link]()
# Explode
[Link](exp_vals,labels=exp_labels, shadow=True,
autopct='%1.1f%%',radius=1.5,explode=[0,0,0,0.2,0.1])
[Link]()
# counterclock and angle properties
[Link](exp_vals,labels=exp_labels, shadow=True, autopct='%1.1f%%',
radius=1.5,explode=[0,0,0,0.1,0.2],counterclock=False, startangle=30)
[Link]()