You are on page 1of 13

University Institute of Engineering

Department of Computer Science & Engineering

Experiment:4

Student Name: Archita Srivastava UID:23BCS12459


Branch: Computer Science & Engineering Section/Group:202-A
Semester:1ST
Subject Name: DISRUPTIVE TECHNOLOGIES-1 Subject
Code: 23ECH-102

1. Aim of the practical: To perform various tasks using matplotlib

2. Tool Used: Google Collaboratory

3. Code:

1. MATPLOTLIB
3.1 To plot a line

Code:-

x=[1,2,3,4,5,6,7]
y=[1,3,2,5,4,7,6] plt.plot(x,y)
plt.title('Amplitude VS Time')
plt.ylabel('Amplitude')
plt.xlabel('Time')
University Institute of Engineering
Department of Computer Science & Engineering

plt.show()

OUTPUT

3.2 To plot multiple lines

Code

x=[1,2,3,4,5,6]
y1=[50,60,50,80,65,100]
y2=[40,50,45,50,100,45]
y3=[70,115,90,100,110,55]
y4=[80,55,90,70,60,50]
plt.plot(x,y1,'g',label='Enfield',linewidth=2)
University Institute of Engineering
Department of Computer Science & Engineering

plt.plot(x,y2,'c',label='Honda',linewidth=1) plt.plot(x,y3,'k',label='Yahama',linewidth=3) plt.plot(x,y4,'y',label='KTM',linewidth=4)


plt.title('Bike details in line plot') plt.ylabel('Distance in kms') plt.xlabel('Days') plt.show()

OUTPUT

3.3 To form a bar graph with 2 values

CODE
4 x=[50,60,30,70,20]
5 y=["A","B","C","D","E"]
6 plt.bar(y,x,color="Green")
University Institute of Engineering
Department of Computer Science & Engineering

7 plt.show()

OUTPUT

3.4 To plot bar graph with more than 2 values

CODE-
x1=[0.25,1.25,2.25,3.25,4.25]
y1=[50,40,70,80,20] plt.bar(x1,y1,
label="BMW",color='r')
x1=[0.75,1.75,2.75,3.75,4.75]
y1=[80,20,20,50,60]
plt.bar(x1,y1, label="AUDI",color='g')
plt.xlabel('Days')
plt.ylabel('Distance (kms)')
plt.title('Information') plt.legend()
University Institute of Engineering
Department of Computer Science & Engineering

plt.show()

OUTPUT

3.5 To plot horizontal bar graph plot

CODE
x=[5,6,3,7,2]
y=["A","B","C","D","E"]
plt.barh(y,x, color="red")
plt.show()
University Institute of Engineering
Department of Computer Science & Engineering

OUTPUT

3.6 To form a graph scatter plot for 2 values

CODE
x=[7,6,3,1,6] y=[3,4,5,6,7]
plt.scatter(x,y)
plt.show()

OUTPUT
University Institute of Engineering
Department of Computer Science & Engineering

3.7 To form a graph scatter plot for more than 2 values

CODE
x1=[0.5,1,1.5,2,2.5]
y1=[6,15,27,38,49]
x2=[0.1,0.2,0.3,0.4,0.5]
y2=[77,78,79,80,81]
plt.scatter(x1,y1,label='H',color='g')
plt.scatter(x2,y2,label='K',color='y')
plt.xlabel('H') plt.ylabel('K')
plt.legend() plt.grid()
plt.show()
University Institute of Engineering
Department of Computer Science & Engineering

OUTPUT

1.8 To form a Pie chart

CODE
grades= 'A','B','C','D','E'
gradecount=[34,89,67,46,98]
plt.pie(gradecount,labels=grades,autopct='%1f%%
') plt.show()

OUTPUT
University Institute of Engineering
Department of Computer Science & Engineering

1.9 To form a pie chart using shade and explore

CODE
grades= 'A','B','C','D','E'

gradecount=[34,89,67,346,98]
plt.pie(gradecount,labels=grades,shadow=True,explode=(0.2,0.3,0,0,0.4),autopct='%1f%% ')
plt.show()
University Institute of Engineering
Department of Computer Science & Engineering

OUTPUT

2 SINE WAVE FORM

CODE
import numpy as np
x=np.arange(0,4*np.pi,0.1)
y=np.sin(x)
plt.plot(x,y)
plt.title("Sine wave form")
plt.show()
University Institute of Engineering
Department of Computer Science & Engineering

OUTPUT

4.Result and Summary: We learn to use python library matplot which helps us to organize
various data into a form that can be easily understood like bar graphs, pie charts etc.

5.Additional Creative Inputs (If Any):

Learning outcomes :Learnt to form various data organizing features such as 1. PLOTTING
LINES 2.BAR GRAPHS 3.SCATTER PLOTS 4.PIE CHARTS 5. SINE WAVE FORM
University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering

You might also like