Page 325 - Informatics_Practices_Fliipbook_Class12
P. 325

Program 16: Two schools have provided data about the average grading of their students over six months.
            School 1: [8, 8.5, 9, 7.2, 8.8, 9.5], School 2: [7.5, 8.0, 8.5, 7.8, 9.0, 9.2].
            Create a single graph with two line plots, one for each school, to compare the monthly performance. The line style
            for School A should be solid and red, and for School B, it should be dashed and blue. Label the axes and provide a
            title. Also, save the figure as "schoolPerformance.png."

            Ans. import matplotlib.pyplot as plt
                 school1grades = [8, 8.5, 9, 7.2, 8.8, 9.5]

                 school2grades = [7.5, 8.0, 8.5, 7.8, 9.0, 9.2]

                 months = ['Month 1', 'Month 2', 'Month 3', 'Month 4', 'Month 5', 'Month 6']
                 plt.figure(figsize=(10, 6))

                 plt.plot(months,        school1grades,       color='red',       linestyle='-',       marker='o',
                 label='School A')
                  plt.plot(months, school2grades, color='blue', linestyle='--', marker='s',
                 label='School B')

                 plt.xlabel('Months')
                 plt.ylabel('Average Grading')

                 plt.title('Monthly Performance Comparison of School A and School B')

                 plt.legend()
                 plt.savefig('schoolPerformance.png')

                 plt.show()

            Program 17: The library keeps a record of the number of books in Fiction, Non-Fiction, and Reference Category borrowed
            in the last four months, as shown below:

                 Month 1: [Fiction: 120, Non-Fiction: 150, Reference: 90]
                 Month 2: [Fiction: 140, Non-Fiction: 160, Reference: 110]

                 Month 3: [Fiction: 130, Non-Fiction: 145, Reference: 100]

                 Month 4: [Fiction: 135, Non-Fiction: 140, Reference: 90]
            Write a Python program to draw a three subgraph each with a line plots for each book category, to compare the
            number of purchases over the past four months. Label the axes and provide a title. Save the figure as "libraryBooks.
            png."

            Ans. import matplotlib.pyplot as plt
                 months = [1, 2, 3, 4]

                 fiction = [120, 140, 130, 135]

                 nonFiction = [150, 160, 145, 140]
                 reference = [90, 110, 100, 90]


                 plt.subplot(3, 1, 1)



                                                                                                      Practical  311
   320   321   322   323   324   325   326   327   328   329   330