Python Matplotlib Programs Record
Python Matplotlib Programs Record
1.
import matplotlib.pyplot as plt
import numpy as np
y1=np.array([1,4,7,9])
y2=np.array([3,6,2,1])
x=np.array(["2006","2007","2008","2009"])
plt.xlabel("YEAR")
plt.ylabel("AFFECTED BY FLU RATE")
plt.title("RATE VS YEAR")
plt.plot(x,y1,linewidth=9,ls="dotted",c="red",label="KER
ALA")
plt.plot(x,y2,linewidth=9,ls="dotted",c="green",label="TA
MILNADU")
plt.legend()
plt.show()
2.
import matplotlib.pyplot as plt
x=["java","python","PHP","javascript","c","c++"]
y1=[22.2,17.6,8.8,8,7.7,6.7]
c=["red","yellow","cyan","green","blue","purple"]
plt.barh(x,y1,color=c)
for index,value in enumerate(y1):
plt.text(value+0.3,index,str(value),va="center")
plt.xlabel("POPULARITY")
plt.ylabel("PROGRAMMING LANGUAGES")
plt.title("Popularity of different programming
languages")
plt.grid()
plt.show()
3.
3.
import matplotlib.pyplot as plt
import numpy as np
i = np.arange(6)+0.5
v1=[2,4,8,5,7,6]
v2=[4,2,3,4,2,6]
v3=[6,4,7,4,7,8]
v4=[8,2,6,4,8,6]
v5=[10,2,4,3,3,2]
bw = 0.3
plt.title('IA-1 MARK COMPARISON BETWEEN
DEPARTMENTS',fontsize=20)
plt.bar(i,v1,bw,color='b')
plt.bar(i+bw,v2,bw,color='g')
plt.bar(i+2*bw,v3,bw,color='r')
plt.bar(i+3*bw,v4,bw,color="y")
plt.bar(i+4*bw,v2,bw,color="c")
plt.bar(i+5*bw,v2,bw,color="w")
plt.xticks(i+bw,['A','B','C','D','E','F'])
plt.show()
4.
import matplotlib.pyplot as plt
labels = ['android','ios','windows','others']
popularity = [10,30,45,15]
colors = ['yellow','green','red','blue']
plt.pie(popularity,labels=labels,colors=colors)
plt.title("POPULARITY OF MOBILE PHONE USAGE")
plt.axis('equal')
plt.show()
5.
import matplotlib.pyplot as plt
import pandas as pd
x=pd.read_csv("medal.csv")
c=x["country"]
gm=x["gold_medal"]
plt.pie(gm,labels=c)
plt.title("GOLD MEDAL ACHIVEMENTS IN 2016 SUMMER
OLYMPICS")
plt.show()
6.
import numpy as np
import matplotlib.pyplot as plt
x=np.arange(10)
math_marks=[88,92,80,89,100,80,60,100,80,34]
science_marks=[35,79,79,48,100,88,32,45,20,30]
plt.scatter(x,science_marks,color="green",label="SCIENC
E MARKS")
plt.scatter(x,math_marks,color="red",label="MATHS
MARKS")
plt.title("MATH VS SCIENCE MARKS")
plt.xlabel("Mathematics marks")
plt.ylabel("Science marks")
plt.legend()
plt.show()
7.
import matplotlib.pyplot as plt
import numpy as np
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
face_cream_sales = [200, 250, 300, 350, 400, 450]
face_wash_sales = [150, 200, 250, 300, 350, 400]
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 6))
ax1.bar(months, face_cream_sales, color='pink')
ax1.set_title('Face Cream Sales')
ax1.set_xlabel('Months')
ax1.set_ylabel('Sales (Units)')
ax1.grid(True)
ax2.bar(months, face_wash_sales, color='lightblue')
ax2.set_title('Face Wash Sales')
ax2.set_xlabel('Months')
ax2.set_ylabel('Sales (Units)')
ax2.grid(True)
plt.show()