Page 114 - Informatics_Practices_Fliipbook_Class12
P. 114
A scatter plot comprises individual data points as markers on a two-dimensional graph. The scatter plot is created
using plt.scatter() function, where the x-axis represents expenses and the y-axis represents revenue.
1. How can you use the method plt.plot() to draw a line graph?
2. How can you use the method for example, plt.plot() to draw a scatter plot?
3.1.4 Plotting Multiple Functions in the Same Graph
Sometimes, we need to compare the behaviour of more than one (say, two) output variables. For example, we may
like to study the average scores obtained by the students after studying for different number of hours in a quiet room
vis-a-vis the average scores obtained by them after studying in a noisy room. In such situations, we plot the performances
under different conditions. First, we plot the students' scores in a quiet room (Fig 3.12).
>>> import matplotlib.pyplot as plt
>>> timeSpentStudying = [1, 2, 3, 4, 5, 6]
>>> quietRoomScores = [63, 75, 82, 87, 93, 100]
>>> plt.plot(timeSpentStudying, quietRoomScores, 'ro-')
>>> plt.xlabel('No of hours studied')
>>> plt.ylabel('Score')
>>> plt.title('Performance in a Quiet Room')
>>> plt.show()
No of hours studies
Fig 3.12: Performance in a Quiet Room
Next, we plot the students' scores in a noisy room (Fig 3.13):
>>> import matplotlib.pyplot as plt
>>> timeSpentStudying = [1, 2, 3, 4, 5, 6]
>>> noisyRoomScores = [58, 62, 68, 69, 75, 80]
>>> plt.plot(timeSpentStudying, noisyRoomScores, 'ro-')
>>> plt.xlabel('No of hours studied')
>>> plt.ylabel('Score')
>>> plt.title('Performance in a Noisy Room')
>>> plt.show()
100 Touchpad Informatics Practices-XII

