Page 113 - Informatics_Practices_Fliipbook_Class12
P. 113
Fig 3.10: Expenses vs. Revenue
It would be instructive to draw a line plot for the revenues (y-axis) vs. the expenses (x-axis) (Fig 3.11)
>>> import matplotlib.pyplot as plt
>>> expenses = [100, 200, 150, 300, 250] # Monthly expenses
>>> revenue = [500, 600, 650, 700, 800] # Monthly revenue
>>> plt.plot(revenue, expenses, 'bo--')
>>> plt.xlabel('Revenue (in INR)')
>>> plt.ylabel('Expenses (in INR)')
>>> plt.title('Revenue vs. Expenses')
>>> plt.show()
Fig 3.11: Expenses vs. Revenue
You must have noted that when we do not specify a line style while invoking the method plt.plot() (for
example, plt.plot(revenue, expenses, 'bo')), we get a scatter plot, but when we specify the line style
(for example, plt.plot(revenue, expenses, 'bo--')), we get a line graph.
Data Visualization 99

