Matplotlib Programs
1. Write a Python program using Matplotlib to plot a line graph showing the
temperature of a city for 7 days:
Days = [1, 2, 3, 4, 5, 6, 7]
Temperature = [22, 24, 21, 25, 27, 26, 28]
2. Write a Python program to create a bar graph showing the monthly sales of a shop:
Months = ["Jan", "Feb", "Mar", "Apr"]
Sales = [12000, 15000, 17000, 16000]
3. Write a Python program to draw a horizontal bar graph showing scores of different
teams:
Teams = ["Team A", "Team B", "Team C", "Team D"]
Scores = [55, 48, 60, 52]
4. Write a Python program to draw a pie chart showing the percentage of expenses in a
month:
Categories = ["Food", "Transport", "Shopping", "Entertainment", "Other"]
Expenses = [5000, 2000, 3000, 1500, 1000]
1. Line Graph – Temperature for 7 Days
import [Link] as plt
days = [1, 2, 3, 4, 5, 6, 7]
temperature = [22, 24, 21, 25, 27, 26, 28]
[Link](days, temperature)
[Link]("Days")
[Link]("Temperature (°C)")
[Link]("Temperature of a City for 7 Days")
[Link]()
2. Bar Graph – Monthly Sales of a Shop
import [Link] as plt
months = ["Jan", "Feb", "Mar", "Apr"]
sales = [12000, 15000, 17000, 16000]
[Link](months, sales)
[Link]("Months")
[Link]("Sales")
[Link]("Monthly Sales of a Shop")
[Link]()
3. Horizontal Bar Graph – Scores of Teams
import [Link] as plt
teams = ["Team A", "Team B", "Team C", "Team D"]
scores = [55, 48, 60, 52]
[Link](teams, scores)
[Link]("Scores")
[Link]("Teams")
[Link]("Scores of Different Teams")
[Link]()
4. Pie Chart – Monthly Expenses
import [Link] as plt
categories = ["Food", "Transport", "Shopping", "Entertainment",
"Other"]
expenses = [5000, 2000, 3000, 1500, 1000]
[Link](expenses, labels=categories, autopct="%1.1f%%")
[Link]("Monthly Expenses Distribution")
[Link]()