DT 2nd Worksheet

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

University Institute of Engineering

Department of Computer Science & Engineering

Experiment: 2

Student Name: PRATIK MISHRA UID: 22BCS15965


Branch: Computer Science & Engineering Section/Group:412-B
Semester: 1 Date of Performance: : 03.10.2022
Subject Name: DISRUPTIVE-TECHNOLGIES
Subject Code: 22ECH-141

1. Aim of the Experiment: 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= [0,1,2,3,4,5,6]
y= [p**13 for p in x]
University Institute of Engineering
Department of Computer Science & Engineering

plt.plot(y)
plt.show()

1.2 Plot a line with details


X=[3,4,5]
y = [2,3,4]

plt.plot(y,X)
plt.title("Graph")
plt.xlabel("X Axis")
plt.ylabel ("Y Axis")
University Institute of Engineering
Department of Computer Science & Engineering

1.3 Plot multiple lines


x = [1, 2, 3, 4, 5]
y1 = [10, 50, 40, 60, 70]
y2 = [20,30,56,78,69]
y3 = [80,34,59,40,55]
y4 = [80, 20, 20, 50, 60]

plt.plot(x, y1, 'b', label='Enfield', linewidth=4)


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

plt.title('Bike details in line plot')


plt.ylabel('Distance in kms')
plt.xlabel('Days')

plt.legend() #Adding Legends

plt.show()
University Institute of Engineering
Department of Computer Science & Engineering

2. Bar plot:
2.1]Plot a bar chart:
x = [30,20,20,10,20]
y = ["CSGO","VALORANT","PUBG","DESTINY 2","C.O.D"]

plt.bar(y, x, color = "blue")

plt.show()

2.2 Multiple bar plot


x1 = [0.25, 1.25, 2.25, 3.25, 4.25]
y1 = [85,68,48,78,65]

plt.bar(x1, y1, label="TESLA", color='r')

x2 = [.75, 1.75, 2.75, 3.75, 4.75]


y2 = [25,60,70,80,55]
plt.bar(x2, y2, label="TATA", color='y')

plt.xlabel('Days')
plt.ylabel('Distance (kms)')
plt.title('Information')

plt.legend()
plt.show()
University Institute of Engineering
Department of Computer Science & Engineering

2.3 Horizontal Bar Plot (barh)


x = [5, 6, 3, 7, 2]
y = ["APPLE", "ORANGE", "MANGO", "BANANA", "POMEGRANATE"]

plt.barh(y, x, color ="purple")

plt.show()
University Institute of Engineering
Department of Computer Science & Engineering

3) Scatter plot:
3.1) Scatter plot:
x = [5, 2, 9, 4, 7] # x-axis values
y = [10, 5, 8, 4, 2] # Y-axis values

plt.scatter(y, x) # Function to plot scatter

plt.show() # function to show the plot

3.2 Scatter plot with title, x-axis and y-axis


x = [35, 20, 29, 40, 57] # x-axis values
y = [30, 50, 60, 40, 20] # Y-axis values

plt.scatter(x, y) # Function to plot scatter

plt.xlabel('Salary * 1000')
plt.ylabel('<Age>')
plt.title('Age Vs Salary')

plt.show() # function to show the plot


University Institute of Engineering
Department of Computer Science & Engineering

3.3 Multiple scatter plot


x1 = [1,1.5,2.5,3.5,4.5,6.7,7.6]
y1 = [7.5,2,3,4,7,9,2,]

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

4. Pie plot
COUNTRIES = 'INDIA','AMERICA','CHINA','RUSSIA','UNITED KINGDOM'
BILLIONAIRES = [30, 200, 140, 50, 30]

plt.pie(BILLIONAIRES, labels=COUNTRIES, autopct='%1.1f%%')


plt.title("<>BILLIONARES IN DIFFERENT COUNTRIES<>")

plt.show()
University Institute of Engineering
Department of Computer Science & Engineering

Example 2

continents = 'ASIA','AFRICA','ANTARTICA','EUROPE'
area = [ '31033131','29648481','13720000','22134900']

colors = ['yellow', 'purple', 'green', 'blue']


explode = (0.2, 0.1, 0.1, 0.1) # explode 1st slice

# Plot
plt.pie(area, explode=explode, labels=continents, colors=colors, shadow = True ,
autopct='%1.1f%%' )
plt.title('\POPULATION IN DIFFERENT CONTINENTS/')

plt.show()
University Institute of Engineering
Department of Computer Science & Engineering

5. Observations, Simulation Screen Shots and Discussions:


1)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. Result and Summary:

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

You might also like