Page 119 - Informatics_Practices_Fliipbook_Class12
P. 119

Fig 3.17:Plotting daily temperature, daily humidity, and daily air quality index for days of a week in
                                                 different subplots of the same graph

            Next, we plot the data about the football matches played by a team (Program 3). For each match, we have the information
            about the number of goals scored, percentage of time the ball was possessed by the team, fouls committed, and the
            number of yellow cards received. We would like to arrange this data in the form of four line graphs, arranged in a
            2x2 matrix. The subplots numbered 1, 2, 3, 4 appear one after the other row-wise. Thus, subplot 1 appears at matrix
            position (1,1), subplot 2 appears at matrix position (1,2), subplot 3 appears at matrix position (2,1), and subplot 4
            appears at matrix position (2,2), as  illustrated in Fig 3.18.

            Program 3: Plotting  data about the football matches played by a team in different subplots of the same graph

              01 import matplotlib.pyplot as plt
              02
              03 # Example data for a football season (20 matches)
              04 matches = list(range(1, 21))
              05 goalsScored = [2, 2, 1, 1, 0, 1, 2, 3, 2, 2, 1, 0, 2, 2, 3, 4, 2, 1, 3, 1]  # goals
              06 per match
              07 possessionPercentage = [53, 53, 57, 57, 45, 55, 53, 48, 52, 50, 55, 47, 54, 55, 56,
              08 58, 50, 53, 49, 51]  # in percentage
              09 foulsCommitted = [12, 12, 14, 14, 11, 16, 10, 14, 13, 12, 10, 15, 13, 14, 13, 16, 11,
              10 12, 14, 10]  # per match
              11 yellowCardsReceived = [2, 2, 3, 3,  1, 2, 1, 2, 1, 1, 1, 2, 3, 2, 1, 3, 2, 1, 2, 1]
              12 # per match
              13
              14 # Create a figure with four subplots
              15 plt.figure(figsize=(12, 8))

                                                                                              Data Visualization  105
   114   115   116   117   118   119   120   121   122   123   124