Python Code for Matplotlib Charts
1. Pie chart for baker's shop sales
Items:
- Ordinary bread: 320
- Fruit Bread: 80
- Cakes and pastries: 160
- Biscuits: 120
- Others: 40
Code:
import matplotlib.pyplot as plt
items = ['Ordinary bread', 'Fruit Bread', 'Cakes and pastries', 'Biscuits', 'Others']
sales = [320, 80, 160, 120, 40]
plt.figure(figsize=(6, 6))
plt.pie(sales, labels=items, autopct='%1.1f%%', startangle=140)
plt.title("Sales in Baker's Shop")
plt.show()
2. Bar graph for marks obtained by students
Students and their Marks:
- Ajay: 450
- Bali: 500
- Dipti: 300
- Faiyaz: 360
- Geetika: 400
- Hari: 540
Code:
import matplotlib.pyplot as plt
students = ['Ajay', 'Bali', 'Dipti', 'Faiyaz', 'Geetika', 'Hari']
marks = [450, 500, 300, 360, 400, 540]
plt.figure(figsize=(8, 5))
plt.bar(students, marks, color='skyblue')
plt.title("Marks Obtained by Students")
plt.xlabel("Students")
plt.ylabel("Marks")
plt.show()
3. Pie chart for creatures in a zoological park
Creatures in Zoological Park:
- Beast Animals: 150
- Other Land animals: 400
- Birds: 225
- Water Animals: 175
- Reptiles: 50
Code:
import matplotlib.pyplot as plt
categories = ['Beast Animals', 'Other Land animals', 'Birds', 'Water Animals', 'Reptiles']
creatures = [150, 400, 225, 175, 50]
plt.figure(figsize=(6, 6))
plt.pie(creatures, labels=categories, autopct='%1.1f%%', startangle=140)
plt.title("Creatures in a Zoological Park")
plt.show()
4. Pie chart for modes of transport used by students
Modes of Transport:
- School Bus: 350
- Private Bus: 245
- Bicycle: 210
- Rickshaw: 175
- On foot: 280
Code:
import matplotlib.pyplot as plt
modes = ['School Bus', 'Private Bus', 'Bicycle', 'Rickshaw', 'On foot']
students_using = [350, 245, 210, 175, 280]
plt.figure(figsize=(6, 6))
plt.pie(students_using, labels=modes, autopct='%1.1f%%', startangle=140)
plt.title("Modes of Transport Used by Students")
plt.show()
5. Pie chart for hours spent on activities by a schoolboy
Activities and Hours:
- School: 7
- Homework: 4
- Play: 2
- Sleep: 8
- Others: 3
Code:
import matplotlib.pyplot as plt
activities = ['School', 'Homework', 'Play', 'Sleep', 'Others']
hours = [7, 4, 2, 8, 3]
plt.figure(figsize=(6, 6))
plt.pie(hours, labels=activities, autopct='%1.1f%%', startangle=140)
plt.title("Hours Spent on Activities by a Schoolboy")
plt.show()
6. Pie chart for workers of different religions
Religions and Workers:
- Hindu: 450
- Nepali: 270
- Islam: 255
- Christian: 105
Code:
import matplotlib.pyplot as plt
religions = ['Hindu', 'Nepali', 'Islam', 'Christian']
workers = [450, 270, 255, 105]
plt.figure(figsize=(6, 6))
plt.pie(workers, labels=religions, autopct='%1.1f%%', startangle=140)
plt.title("Workers of Different Religions")
plt.show()