PYPLOT ASSIGNMENT
import matplotlib.pyplot as plt
a=[20,30,40,50]
b=[2,4,6,8]
plt.plot(a,b)
plt.show()
#2
def fnplot(list1):
plt.plot(list1)
plt.title("Marks
Line Chart")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.show()
list1=[50,50,50,65,65,75,75,80,80,90,90,90,90]
fnplot(list)
#3
plt.plot([1,2,3,4],[1,4,9,16])
plt.show()
plt.plot([1,2,8,4],[1,4,9,16])
plt.title("First Plot")
plt.xlabel(" X Label")
plt.ylabel("Y Label")
plt.show()
#5
plt.figure(figsize=(4,4))
plt.plot([1,2,3,4],[1,4,9,16])
plt.title("First Plot")
plt.xlabel(" X Label")
plt.ylabel("Y Label")
plt.show()
#5
plt.plot([12,23,30,47])
plt.title("Second Plot")
plt.xlabel(" X Label")
plt.ylabel("Y Label")
plt.show()
#6
plt.subplot(1,2,1) #the figure has 1 row, 2 columns, and
this plot is the first plot.
plt.plot([1,2,3,4],[1,4,9,16],"go")
plt.title("First Plot")
plt.subplot(1,2,2)
plt.plot([1,2,3,4],[1,4,9,16],"r^")
plt.title("Second Plot")
plt.show()
HISTOGRAM
import numpy as np
import matplotlib.pyplot as p1
a = np.array([22,87,5,43,56,73,55,54,11,20,51,5,79,31,27])
p1.hist(a, bins = [0,25,50,75,100],facecolor='y',edgecolor="red")
p1.title("histogram of result")
p1.xticks([0,25,50,75,100])
p1.xlabel('marks')
p1.ylabel('no. of students')
p1.show()
data_students=[1,11,21,31,41,51]
plt.hist(data_students,bins=[0,10,20,30,40,50,60],weights=[10,1,0,33,6,8],
facecolor='y',edgecolor="red")
plt.title("Histogram for Students data")
plt.xlabel('Value')
plt.ylabel('Frequency')
#plt.savefig("student.png")
plt.show()
#EG: HISTOGRAM
import matplotlib.pyplot as plt
data_students=[5,15,25,35,45,55]
plt.hist(data_students,bins=[0,10,20,30,40,50,60],weights=[20,10,45,33,6,8],
facecolor='y',edgecolor="red")
plt.title("Histogram for Students data")
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.savefig("student.png")
plt.show()
#7
import matplotlib.pyplot as plt
import numpy as np
xpoints = np.array([0, 6])
ypoints = np.array([0, 250])
plt.plot(xpoints, ypoints)
plt.show()
#8
city=['del','mum','chandig','bang']
popu=[23456,5000,1876,1234]
plt.bar(city,popu)
plt.show()
'''
#9
import numpy as np
x=np.arange(1,5)
y=x**3
print(x)
print(y)
#plt.plot([1,2,3,4],[1,4,9,16],"go",x,y,'r^')
plt.title("First Plot")
plt.xlabel(" X Label")
plt.ylabel("Y Label")
plt.plot(x,y,'y')
plt.plot(x,y,"r^")
plt.show()
#10
plt.subplot(1,2,1)
plt.plot([1,2,3,4],[1,4,9,16],"bo")
plt.title("First Plot")
plt.subplot(1,2,2)
plt.plot([1,2,3,4],[1,8,9,20],"r^")
plt.title("Second Plot")
plt.show()
#11.
import matplotlib.pyplot as plt
import numpy as np
ypoints = np.array([3, 8, 1, 10])
plt.plot(ypoints, marker = 'o')
#or
plt.plot(ypoints, marker = '*')
plt.show()
#12.
import matplotlib.pyplot as plt
import numpy as np
ypoints = np.array([3, 8, 1, 10])
plt.plot(ypoints, linestyle = 'dotted')
plt.show()
Comments
Post a Comment