Page 120 - Informatics_Practices_Fliipbook_Class12
P. 120
16
17 # Subplot 1: Goals Scored by the team
18 plt.subplot(2, 2, 1) # 2 rows, 2 columns, subplot 1
19 plt.plot(matches, goalsScored, marker='o')
20 plt.xlabel('Match')
21 plt.ylabel('Goals Scored')
22 plt.title('Goals Scored')
23
24 # Subplot 2: Percentage of time the team possed the ball
25 plt.subplot(2, 2, 2) # 2 rows, 2 columns, subplot 2
26 plt.plot(matches, possessionPercentage, marker='o')
27 plt.xlabel('Match')
28 plt.ylabel('Possession (%)')
29 plt.title('Possession Time (% of total time)')
30
31 # Subplot 3: Number of Fouls Committed by the team
32 plt.subplot(2, 2, 3) # # 2 rows, 2 columns, subplot 3
33 plt.plot(matches, foulsCommitted, marker='o')
34 plt.xlabel('Match')
35 plt.ylabel('Fouls Committed')
36 plt.title('Fouls Committed')
37
38 # Subplot 4: Yellow Cards Received
39 plt.subplot(2, 2, 4) # # 2 rows, 2 columns, subplot 4
40 plt.plot(matches, yellowCardsReceived, marker='o')
41 plt.xlabel('Match')
42 plt.ylabel('Yellow Cards Received by the Team')
43 plt.title('Yellow Cards Received by the Team')
44
45 # Adjust layout and show the plots
46 plt.tight_layout()
47 plt.show()
Fig 3.18: Plotting data of a football season in different subplots of the same graph
106 Touchpad Informatics Practices-XII

