Page 324 - Informatics_Practices_Fliipbook_Class12
P. 324

plt.title('Annual Budget Allocations for Government Departments')

             plt.savefig('budgetAllocation.png')

             plt.show()

         Program 14: Utilizing government data, plot a scatter graph that illustrates the correlation between government
         spending (in billions of dollars) and GDP (in billions of dollars) for a country over five years. Use red crosses as markers.
         Label the axes and provide a title. Save the figure as "governmentScatter.png."

             years = [2019, 2020, 2021, 2022, 2023]

             spending = [150, 155, 160, 165, 170]

             gdp = [2000, 2050, 2100, 2150, 2200]
        Ans. import matplotlib.pyplot as plt

             years = [2019, 2020, 2021, 2022, 2023]

             governmentSpending = [150, 155, 160, 165, 170]
             gdp = [2000, 2050, 2100, 2150, 2200]

             plt.scatter(governmentSpending, gdp, marker='x', color='red')

             plt.xlabel('Government Spending (in billions of dollars)')
             plt.ylabel('GDP (in billions of dollars)')

             plt.title('Correlation between Government Spending and GDP Over Five Years')
             plt.savefig('governmentScatter.png')

             plt.show()

         Program 15: Consider the following data comprising train departure delays and arrival delays for ten different trains:

             departureDelays = [5, 8, 2, 15, 3, 12, 6, 4, 9, 7]

             arrivalDelays = [10, 12, 7, 18, 8, 15, 10, 9, 14, 11]
        Write a Python program to generate a scatter plot representing relationship between these departure delays and
        arrival delays for ten different trains. Use orange circles as markers and label the axes and add appropriate title.
        Save the figure as "delayCorrelation.png."

        Ans. import matplotlib.pyplot as plt

             departureDelays = [5, 8, 2, 15, 3, 12, 6, 4, 9, 7]

             arrivalDelays = [10, 12, 7, 18, 8, 15, 10, 9, 14, 11]
             plt.scatter(departureDelays, arrivalDelays, c='orange', marker='o')

             plt.xlabel('Departure Delays')

             plt.ylabel('Arrival Delays')
             plt.title('Departure Delays vs. Arrival Delays')

             plt.savefig('delayCorrelation.png')

             plt.show()


          310  Touchpad Informatics Practices-XII
   319   320   321   322   323   324   325   326   327   328   329