Page 134 - Informatics_Practices_Fliipbook_Class12
P. 134

# Display the plot
              plt.show()


              Output:






























          12.  Collect and store data related to the screen time of students in your class separately for boys and girls and present it using
              a boxplot.

         Ans.  import matplotlib.pyplot as plt
              import pandas as pd
              import numpy as np

              boysScreenTime = [8,5,6,10,11,9,7,16,2,4]
              girlsScreenTime = [4,10,11,12,2,3,8,7,13,14]


              # Create a DataFrame
              data = pd.DataFrame({
                  'Gender': ['Boy'] * 10 + ['Girl'] * 10,
                  'ScreenTime': np.concatenate([boysScreenTime, girlsScreenTime])
              })


              # Plotting
              plt.figure(figsize=(8, 6))
              plt.boxplot([data[data['Gender'] == 'Boy']['ScreenTime'], data[data['Gender'] == 'Girl']
              ['ScreenTime']],
                          labels=['Boys', 'Girls'])
              plt.title('Screen Time of Students by Gender')
              plt.xlabel('Gender')
              plt.ylabel('Screen Time (hours)')
              plt.show()








          120  Touchpad Informatics Practices-XII
   129   130   131   132   133   134   135   136   137   138   139