Assignment of Matplotlib-Prem
Assignment of Matplotlib-Prem
Page | 0
Bar Graph
Page | 1
# Set x and y axis labels
plt.xlabel("Customer Age")
plt.ylabel("Customer Limit")
# Set the title
plt.title("Customer Acquisition")
# Display the graph
plt.show()
Page | 2
1. Histogram
import matplotlib.pyplot as plt
import pandas as pd
#take individual Customer ages and range of ages
Cust_age=[76,71,34,47,56,70,26,67,79,54,51,29,16,25,52]
bins=[0,10,20,30,40,50,60,70,80]
#create histogram
plt.hist(Cust_age,bins,histtype='bar',rwidth=0.8,color='blue')
#set labels
plt.xlabel('Customer age')
Page | 3
plt.ylabel('No. of Customers')
plt.title('Customer Acquisition')
plt.legend()
plt.show()
Page | 4
3.LineGraph
import matplotlib.pyplot as plt
City=["BANGALORE","CALCUTTA","COCHIN","BOMBAY","DELHI"]
Age=[76,71,34,47,56]
plt.plot(City,Age,"blue")
plt.title("Customer Acquisition")
plt.xlabel("City")
plt.ylabel("Age")
plt.show()
Page | 5
4. Scatter plot
Age = [51,29,16,25,52]
Limit = [500000,100000,10000,10001,10002]
plt.subplot(2, 2, 4)
plt.scatter(x, y, label='Scatter Data', color='green')
plt.xlabel('Age')
plt.ylabel('Limit')
plt.title('Scatter Plot')
plt.tight_layout() # To ensure proper spacing
plt.show()
Page | 6
5.Pie Chart
import matplotlib.pyplot as plt
#take expenditure of 4 departments
slices = [50,10,24,16]
#take department name
depts = ["Self Employed","Salaried_MNC","Salaried_Pvt","Govt"]
#take colour to each department
cols = ['red', 'green' , 'blue', 'yellow']
#create a pie chat
plt.pie(slices, labels=depts, colors=cols, startangle=90, autopct='%.1f%%')
plt.title("Customer Acquisition")
plt.legend()
plt.show()
Page | 7
Page | 8