Page 296 - AI Ver 3.0 Class 11
P. 296

Example: Let us consider the average temperature in Delhi and then draw a line graph from the available data:

                Month           Jan    Feb    Mar    Apr     May    Jun    Jul     Aug    Sep    Oct    Nov     Dec

                Temperature     10     15     25     37      45     47     46      40     38     30     25      16

























              Program 5: Create a Line Graph for different temperature in different months using Python.

               Month             Jan    Feb    Mar    Apr     May    Jun    Jul     Aug    Sep    Oct    Nov     Dec

               Temperature       10     15     25     37      45     47     46      40     38     30     25      16






              import matplotlib.pyplot as plt


              # Sample data for the line graph
              months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov',
              'Dec']
              temperatures = [10, 15, 25, 37, 45, 47, 46, 40, 38, 30, 25, 16]


              ' ' ' Create a line graph using plot() function with customized markers, linewidth, and
              linestyle' ' '
              plt.plot(months, temperatures,
                       marker='o', markersize=8, markeredgecolor='red',
                       linestyle='--', linewidth=2, color='b', label='Temperature')

              # Add titles and labels
              plt.title('Average Monthly Temperatures in Delhi')
              plt.xlabel('Month')
              plt.ylabel('Temperature (°C)')


              # Show the legend
              plt.legend()






                    294     Touchpad Artificial Intelligence (Ver. 3.0)-XI
   291   292   293   294   295   296   297   298   299   300   301