University Institute of Engineering
Department of Computer Science & Engineering
Experiment: 2
Student Name: SNEHASIS MEDDA UID: 22BCS16163
Branch: Computer Science & Engineering Section/Group: 22BCS412-A
Semester: 1 ST Date of Performance: 03.10.2022
Subject Name: DISRUPTIVE TECHNOLOGIES Subject Code: 22ECH-102
1. Aim of the practical: Learning the use of
1. Graphical representation of information and data
2. Graph, Chart, and Map making to easily understand the patterns in data
3. Matplotlib for creating static, animated, and interactive visualizations in Python.
2. Tool Used: Google colab
3.Code :
Import matplotlib
import matplotlib.pyplot as plt
1. Line plot :
1.1 Plot a line :
x= [1,2,3,4,5]
y= [i** 4 for i in x]
plt.plot(x,y)
plt.show()
University Institute of Engineering
Department of Computer Science & Engineering
OUTPUT:
To save plot in a file
plt.savefig("Image.jpg", dpi=600)
1.2 Plot a line with details :
x = [2,4,8]
y = [3,4,7]
plt.plot(x,y)
plt.title("Graph")
plt.xlabel("X Axis")
plt.ylabel ("Y Axis")
plt.show()
OUTPUT:
University Institute of Engineering
Department of Computer Science & Engineering
1.3 Plot multiple lines :
x = [2018, 2019, 2020, 2021, 2022]
y1 = [20,40,40,50,60]
y2 = [50,70,80,90,130]
y3 = [10,30,50,40,70]
plt.plot(x, y1, 'b', label ='Book 1', linewidth =2)
plt.plot(x, y2, 'g', label ='Book 2', linewidth =2)
plt.plot(x, y3, 'c', label ='Book 3', linewidth =2)
plt.title("SELLING OF BOOKS")
plt.xlabel("Year")
plt.ylabel("No of books")
plt.legend()
plt.show()
OUTPUT:
University Institute of Engineering
Department of Computer Science & Engineering
2. Bar plot :
2.1 Plot a bar chart :
x = ['CSE', 'ECE', 'Civil', 'IT', 'Chemical' ]
y = [1000,400,200,800,300]
plt.bar(x,y,color='blue')
plt.show()
OUTPUT:
2.2 Multiple bar plot :
x = ['2021 Q1','2021 Q2', '2021 Q3', '2021 Q4']
y1 = [ 300, 400, 200, 250 ]
y2 = [ 250,300,200,300]
plt.bar(x,y1, label='BMW', color='green',width=0.5)
plt.bar(x,y2, label='Audi', color='yellow',width=0.5)
plt.title('Sales')
plt.xlabel('Quaters')
plt.ylabel('X 1000 $')
plt.legend()
plt.show()
University Institute of Engineering
Department of Computer Science & Engineering
OUTPUT:
2.3 Horizontal Bar Plot (barh) :
x = [5, 6, 3, 7, 2]
y = ["A", "B", "C", "D", "E"]
plt.barh(y, x, color ="orange")
plt.show()
OUTPUT:
University Institute of Engineering
Department of Computer Science & Engineering
3. Scatter plot :
3.1 Scatter plot :
x = [2,5,7,8,6]
y = [3,5,6,9,8]
plt.scatter(x, y)
plt.show()
OUTPUT:
3.2 Scatter plot with title, x-axis and y-axis :
x = [40,45,50,55,60,65,70,75,80]
y = [145,165,150,173,169,180,155,160,162]
plt.scatter(x,y, color='g')
plt.title('Age Vs Weight')
plt.xlabel('Age(years)')
plt.ylabel('Weight(KG)')
plt.show()
University Institute of Engineering
Department of Computer Science & Engineering
OUTPUT:
3.3 Multiple scatter plot :
x1 = [1, 1.5, 2, 2.5, 3, 3.5, 3.6]
y1 = [7.5, 8, 8.5, 9, 9.5, 10, 10.5]
x2 = [8, 8.5, 9, 9.5, 10, 10.5, 11]
y2 = [3, 3.5, 3.7, 4, 4.5, 5, 5.2]
plt.scatter(x1, y1, label='High income low saving', color='r')
plt.scatter(x2, y2, label='Low income high savings', color='b')
plt.xlabel('Saving*100')
plt.ylabel('Income*1000')
plt.title('Scatter Plot')
plt.legend()
plt.grid()
plt.show()
University Institute of Engineering
Department of Computer Science & Engineering
OUTPUT:
4. Pie plot :
1.
country = 'India','Japan', 'China' ,'Russia','France','USA'
people =[138,12.58,140,14.41,6.74,32.95]
colors = ['blue','orange','green','skyblue','violet','brown']
plt.pie(people,colors=colors,autopct = '%1.1f%%')
plt.legend(labels=country,loc='best')
plt.axis('equal')
plt.title('Population')
plt.show()
OUTPUT:
University Institute of Engineering
Department of Computer Science & Engineering
2.
share = [3,5,2,2.5,0.5]
bikes = ['Enfield','Honda','Yahama','KTM','Kawasaki']
color = ['grey','red','blue','orange','green']
plt.pie(share, labels=bikes, shadow= True, colors=color, explode=(0.1,0.1,0.1,0.1,0.1
),
autopct='%1.1f%%')
plt.title('Bike Shares')
plt.show()
OUTPUT:
University Institute of Engineering
Department of Computer Science & Engineering
5. Observations, Simulation Screen Shots and Discussions:
Line plot:
University Institute of Engineering
Department of Computer Science & Engineering
2. Bar Plot :
University Institute of Engineering
Department of Computer Science & Engineering
3.Scatter Plot :
University Institute of Engineering
Department of Computer Science & Engineering
4. Pie Plot :
University Institute of Engineering
Department of Computer Science & Engineering
6. Learning outcomes (What I have learnt):
1. use of ‘matplotlib’
2. Graphical representation of data
3. various graphs plotting in python
7. Evaluation Grid (To be filled by Faculty):
Sr. No. Parameters Marks Obtained Maximum Marks
1. Student Performance (task 12
implementation and result evaluation)
2. Viva-Voce 10
3. Worksheet Submission (Record) 8
Signature of Faculty (with Date): Total Marks Obtained: 30