Page 127 - Informatics_Practices_Fliipbook_Class12
P. 127

Ans.      import matplotlib.pyplot as plt
                      months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
                      datasetX = [100, 120, 150, 130, 140, 160]
                      datasetY = [80, 90, 110, 100, 120, 130]
                      plt.plot(months, datasetX, marker='o', label='Dataset X')
                      plt.plot(months, datasetY, marker='o', label='Dataset Y')
                      plt.xlabel('Months')
                      plt.ylabel('Revenue')
                      plt.title('Revenue Trends of Dataset X and Dataset Y')
                      plt.legend()
                      plt.show()






















                                                     Line plot of Revenue Trends

               3.  Consider the following list representing scores of 30 students in a mathematics test in XI class.
                  [78, 85, 90, 72, 88, 95, 82, 79, 87, 83, 78, 92, 84, 88, 75, 80, 86, 89, 91, 94, 77, 81, 83, 90, 85, 87, 92, 95, 88, 84]
                  Write a Python program to create a histogram to visualize the distribution of scores using Matplotlib.
             Ans.      import matplotlib.pyplot as plt
                      scores = [78, 85, 90, 72, 88, 95, 82, 79, 87, 83, 78, 92, 84, 88, 75, 80, 86, 89,
                      91, 94, 77, 81, 83, 90, 85, 87, 92, 95, 88, 84]
                      plt.hist(scores, bins=[60, 65, 70, 75, 80, 85, 90, 95, 100], edgecolor='black',
                      alpha=0.7)
                      plt.xlabel('Scores')
                      plt.ylabel('Frequency')
                      plt.title('Distribution of Scores in Mathematics Test')
                      plt.show()


















                                     Histogram depicting the distribution of scores in Mathematics Test

                                                                                              Data Visualization  113
   122   123   124   125   126   127   128   129   130   131   132