Page 326 - Informatics_Practices_Fliipbook_Class12
P. 326
plt.plot(months, fiction, label='Fiction')
plt.xlabel('Month')
plt.ylabel('Number of Books Purchased')
plt.title('Books purchased in Fiction Category')
plt.legend()
plt.subplot(3, 1, 2)
plt.plot(months, nonFiction, label='Non-Fiction')
plt.xlabel('Month')
plt.ylabel('Number of Books Purchased')
plt.title('Books purchased in Non-Fiction Category')
plt.legend()
plt.subplot(3, 1, 3)
plt.plot(months, reference, label='Reference')
plt.xlabel('Month')
plt.ylabel('Number of Books Purchased')
plt.title('Books purchased in Reference Category')
plt.legend()
plt.savefig('libraryBooks.png')
plt.show()
Program 18: Consider the sales of five different dishes in a restaurant using restaurant data:
dishes = ["Spaghetti Carbonara", "Margherita Pizza", "Grilled Salmon", "Chicken
Alfredo", "Vegetable Stir-Fry"]
sales = [120, 180, 90, 150, 100]
Write a Python program to create a bar graph comparing sales of these dishes using distinct colours. Label the axes
and provide a title. Save the figure as "dishSalesComparison.png."
Ans. import matplotlib.pyplot as plt
dishes = ['Spaghetti Carbonara', 'Margherita Pizza', 'Grilled Salmon', 'Chicken
Alfredo', 'Vegetable Stir-Fry']
sales = [120, 180, 90, 150, 100]
colors = ['b', 'g', 'r', 'c', 'm']
plt.bar(dishes, sales, color=colors)
plt.xlabel('Dishes')
plt.ylabel('Sales')
plt.title('Sales Comparison of Restaurant Dishes')
plt.savefig('dishSalesComparison.png')
plt.show()
312 Touchpad Informatics Practices-XII

