Matplotlib line graph

# Creating a line graph using matplotlib


 """

Before executing the program install matplotlib


open command prompt and type


    pip install matplotlib

   

this will install all required packages


"""


# importing the required module 

import matplotlib.pyplot as plt 

    

# x axis values 

x = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] 


# corresponding y axis values 

y1 = [24.3, 25.3, 27.4, 29.6, 30.8, 30.3, 30, 29.2, 28.7, 27.3, 25.7, 24.6] 

y2 = [23.9, 25.8, 28.1, 28.9, 27.5, 25.2, 24.5, 24.5, 25, 24.8, 23.9, 23.2]  


# Setting the width and height of graph

f = plt.figure()

f.set_figwidth(12)

f.set_figheight(4)


# plotting the points  

plt.plot(x, y1, 'g', label='Chennai', linewidth=2.5) 

plt.plot(x, y2, 'r', label='Coimbatore', linewidth=2.5)

    

# naming the x axis 

plt.xlabel('Month') 


# naming the y axis 

plt.ylabel('Temperature') 


# display legend

plt.legend()

    

# giving a title to my graph 

plt.title('Monthly Avarage Temperature') 

    

# function to show the plot 

plt.show() 


"""

Output



"""





No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu