0% found this document useful (0 votes)
64 views

Assignment of Matplotlib-Prem

This document provides code examples and explanations for creating different types of charts and graphs using the Matplotlib library in Python, including: 1. A bar graph comparing customer age and limit using DataFrames. 2. A histogram of customer ages using bins and custom labels/titles. 3. A line graph plotting city names against customer ages. 4. A scatter plot graphing customer age versus limit. 5. A pie chart displaying expenditure percentages for different departments with custom colors.

Uploaded by

Aditya patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Assignment of Matplotlib-Prem

This document provides code examples and explanations for creating different types of charts and graphs using the Matplotlib library in Python, including: 1. A bar graph comparing customer age and limit using DataFrames. 2. A histogram of customer ages using bins and custom labels/titles. 3. A line graph plotting city names against customer ages. 4. A scatter plot graphing customer age versus limit. 5. A pie chart displaying expenditure percentages for different departments with custom colors.

Uploaded by

Aditya patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

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 matplotlib.pyplot 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 = pd.DataFrame(custdata)
# Extract Age and Limit data for the bar graph
x = df["Age"]
y = df["Limit"]
# Create a bar graph
plt.bar(x, y, label='Customerdata', color='red')

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

You might also like