Page 133 - Informatics_Practices_Fliipbook_Class12
P. 133
# Display the plot
plt.show()
Output:
11. Collect data about colleges in Delhi University or any other university of your choice and number of courses they run for
Science, Commerce and Humanities, store it in a CSV file and present it using a bar plot.
Ans: We can manually create a CSV file named "delhi_university_courses.csv" with columns such as "College", "Science
Courses", "Commerce Courses", and "Humanities Courses."
Example CSV content:
College,Science Courses,Commerce Courses,Humanities Courses
Deen Dayal Upadhyaya College,10,1,5
Dyal Singh College,9,3,40
Hans Raj College,10,2,10
Python Code to draw a Barplot:
import pandas as pd
import matplotlib.pyplot as plt
# Read data from CSV
df = pd.read_csv('delhi_university_courses.csv')
# Plotting
df.plot(x='College', kind='bar', stacked=True, colormap='')
plt.title('Number of Courses by College and Stream')
plt.xticks(rotation=10)
plt.xlabel('College')
plt.ylabel('Number of Courses')
plt.legend(title='Stream', loc='upper right')
Data Visualization 119

