Page 323 - Informatics_Practices_Fliipbook_Class12
P. 323
plt.ylabel('Tax Revenue (in lakhs)')
plt.title('Monthly Tax Revenue Trends (Year)')
plt.grid(True)
plt.savefig('taxRevenue.png')
plt.show()
Program 12: Given the dataset comprising the number of passengers traveling on a specific train route over a week:
[130, 155, 205, 180, 220, 245, 290]. Write a Python program using Matplotlib to create a line plot with markers
to visualize the passenger trends. The line should appear as dashed blue line with markers depicted by squares.
Provide appropriate labels for the axis and title for the Figure. The Figure should have gridlines and should be saved
as "passengerTrends.png."
Ans. import matplotlib.pyplot as plt
passengerData = [130, 155, 205, 180, 220, 245, 290]
plt.plot(passengerData, linestyle='--', marker='s', color='blue', label='Passenger
Trends')
plt.xlabel('Day of the Week')
plt.ylabel('Number of Passengers')
plt.title('Passenger Trends Over a Week')
plt.grid(True)
plt.legend()
plt.savefig('passengerTrends.png')
plt.show()
Program 13: Consider four government departments, namely, Education, Healthcare, Infrastructure, and Security
with their annual budget allocations as 200, 250, 180, and 300 million dollars, respectively. Create a bar graph to
compare the annual budget allocations for these different government departments. Provide labels for the axis,
title for the Figure, and save it as "budgetAllocation.png."
Ans. import matplotlib.pyplot as plt
educationBudget = 200
healthcareBudget = 250
infrastructureBudget = 180
securityBudget = 300
departments = ['Education', 'Healthcare', 'Infrastructure', 'Security']
budgets = [educationBudget, healthcareBudget, infrastructureBudget, securityBudget]
plt.bar(departments, budgets)
plt.xlabel('Government Departments')
plt.ylabel('Annual Budget Allocation (in million dollars)')
Practical 309

