Assignment Of Matplotlib
Name: -Prem Jakhate
Programme:- BBA-
IT(2021-24)
Div:-A
PRN:- 21030122075
Index Page No.
Bar Graph 1-3
Histogram 3-4
Line Graph 5
Scatter Plot 6
Pie chart 7-8
Page | 0
Bar Graph
#pip install matplotlib
import [Link] as plt
import pandas as pd
custdata = {
"Age": [34,47,56,71,80,],
"City":
["BANGALORE","CALCUTTA","COCHIN","BOMBAY","BANGALORE"],
"Limit": [500000,100000,200000,250000,370000],
"Segment": ["Self Employed","Salaried_MNC","Salaried_Pvt","Govt","Normal
Salary"]
}
# Create a DataFrame
df = [Link](custdata)
# Extract Age and Limit data for the bar graph
x = df["Age"]
y = df["Limit"]
# Create a bar graph
[Link](x, y, label='Customerdata', color='red')
Page | 1
# Set x and y axis labels
[Link]("Customer Age")
[Link]("Customer Limit")
# Set the title
[Link]("Customer Acquisition")
# Display the graph
[Link]()
Page | 2
1. Histogram
import [Link] 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
[Link](Cust_age,bins,histtype='bar',rwidth=0.8,color='blue')
#set labels
[Link]('Customer age')
Page | 3
[Link]('No. of Customers')
[Link]('Customer Acquisition')
[Link]()
[Link]()
Page | 4
[Link]
import [Link] as plt
City=["BANGALORE","CALCUTTA","COCHIN","BOMBAY","DELHI"]
Age=[76,71,34,47,56]
[Link](City,Age,"blue")
[Link]("Customer Acquisition")
[Link]("City")
[Link]("Age")
[Link]()
Page | 5
4. Scatter plot
Age = [51,29,16,25,52]
Limit = [500000,100000,10000,10001,10002]
[Link](2, 2, 4)
[Link](x, y, label='Scatter Data', color='green')
[Link]('Age')
[Link]('Limit')
[Link]('Scatter Plot')
plt.tight_layout() # To ensure proper spacing
[Link]()
Page | 6
[Link] Chart
import [Link] 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
[Link](slices, labels=depts, colors=cols, startangle=90, autopct='%.1f%%')
[Link]("Customer Acquisition")
[Link]()
[Link]()
Page | 7
Page | 8