SlideShare ist ein Scribd-Unternehmen logo
1 von 36
DATA
VISUALIZATION
(matplotlib.pyplot)
Data Visualization
 Purpose of plotting;
 drawing and saving following types of plots using
matplotlib – line plot, bar graph, histogram, pie
chart, frequency polygon, box plot and scatter
plot.
 Customizing plots: color, style (dashed, dotted),
width; adding label, title, and legend in plots.
1
Sangita Panchal
Purpose of Plotting 2
Sangita Panchal
 One of the most popular uses for Python is data analysis.
Data scientists want a way to visualize their data to get a
better grasp of the data, and to convey their results to
someone.
 Matplotlib is a Python library used for plotting. It is used to
create 2d Plots and graphs easily and control font properties,
line controls, formatting axes, etc. through Python script.
Line Chart 3
Sangita Panchal
import matplotlib.pyplot as plt
plt.plot([1,2,3],[4,5,1])
plt.show()
import matplotlib.pyplot as plt
plt.plot([4,5,1])
plt.show()
Line Chart 3
Sangita Panchal
import matplotlib.pyplot as plt
plt.plot([‘A’,’B’,’C’],[4,5,1])
plt.show()
import matplotlib.pyplot as plt
plt.plot([1,5],[2,6])
plt.show()
Line Chart
Try all the commands
4
Sangita Panchal
import matplotlib.pyplot as plt
x = ['A1','B1','C1']
y = [31,27,40]
x1 = ['A1','B1','C1','D1']
y1 = [12,20,19,17]
plt.plot(x,y,label = "Sr. School")
plt.plot(x1,y1,label = "Jr.School")
plt.title("Bus Info")
plt.ylabel("No. of Students")
plt.xlabel("Bus No.")
plt.legend()
plt.savefig("businfo")
plt.show()
Title
xlabel
ylabel Legend
Line Chart 5
Sangita Panchal
Save the figure
plt.savefig(“linechart.pdf”)
# saves in the current directory
plt.savefig(“c:datamultibar.pdf”)
# saves in the given path
plt.savefig(“c:datamultibar.png”)
# saves in the given path in .png format
Bar Chart 9
Sangita Panchal
import matplotlib.pyplot as plt
# Students in each section
x = ['A','B','C','D','E']
y = [31,27,40,43,45]
plt.bar(x,y,label = "No.of students")
plt.title("Section wise number of students")
plt.ylabel("No. of Students")
plt.xlabel("Section")
plt.legend()
plt.show()
Bar Chart Horizontal 10
Sangita Panchal
import matplotlib.pyplot as plt
# Students in each section
x = ['A','B','C','D','E']
y = [31,27,40,43,45]
plt.barh(x,y,label = "No.of students")
plt.title("Section wise number of students")
plt.ylabel("No. of Students")
plt.xlabel("Section")
plt.legend()
plt.show()
Bar Chart Stacked 11
Sangita Panchal
import matplotlib.pyplot as plt
# Number of students in each bus
x = [‘A’, ‘B’, ‘C’, ‘D’]
y = [31,27,40,32]
y1 = [12,20,19,17]
plt.bar(x,y,label = "Sr. School")
plt.bar(x,y1,label = "Jr.School")
plt.title("Bus Info")
plt.ylabel("No. of Students")
plt.xlabel("Bus No.")
plt.legend()
plt.show()
Bar Chart – Multiple 12
Sangita Panchal
import matplotlib.pyplot as plt
import numpy as np
# Number of students in each bus
x = np.arange(1,5)
y = [31,27,40,32]
y1 = [12,20,19,17]
plt.bar(x+0,y,label = "Sr. School",width = 0.4)
plt.bar(x+0.4,y1,label = "Jr.School",width = 0.4)
plt.title("Bus Info")
plt.ylabel("No. of Students")
plt.xlabel("Bus No.")
plt.legend()
plt.show()
Histogram 13
Sangita Panchal
import matplotlib.pyplot as plt
import numpy as np
# Marks obtained by 50 students
x = [5,15,20,25,35,45,55]
y = np.arange(0,61,10)
w = [2,3,8,9,12,6,10]
plt.hist(x,bins = y, weights = w,
label = "Marks Obtained")
plt.title("Histogram")
plt.ylabel("Marks Range")
plt.xlabel("No. of Students")
plt.legend()
plt.show()
Histogram 13
Sangita Panchal
import matplotlib.pyplot as plt
import numpy as np
# Marks obtained by 50 students
x = [5,15,20,25,35,45,55,70,84,90,93]
y = [0,33,45,60,75,90,100]
w = [2,3,8,9,12,6,10,5,8,12,7]
plt.hist(x,bins = y, weights = w,
label = "Marks Obtained",
edgecolor = "yellow")
plt.title("Histogram")
plt.ylabel("Marks Range")
plt.xlabel("No. of Students")
plt.legend()
plt.show()
Difference between Bar graph and Histogram 13
Sangita Panchal
Difference between Bar graph and Histogram 14
Sangita Panchal
Histogram Bar
Histogram is defined as a type of bar chart that to
show the frequency distribution of continuous data.
It indicates the number of observations which lie in-
between the range of values, known as class or bin.
Take the observations and split them into logical
series of intervals called bins.
X-axis indicates, independent variables i.e. bins
Y-axis represents dependent variables i.e.
occurrences.
Rectangle blocks i.e. bars are shown on the x-axis,
whose area depends on the bins.
A bar graph is a chart that represents the comparison
between categories of data.
It displays grouped data by way of parallel rectangular
bars of equal width but varying the length.
Each rectangular block indicates specific category and
the length of the bars depends on the values they
hold. The bars do not touch each other.
Bar diagram can be horizontal or vertical, where a
horizontal bar graph is used to display data varying
over space whereas the vertical bar graph represents
time series data. It contains two axis, where one axis
represents the categories and the other axis shows
the discrete values of the data.
Difference between Bar graph and Histogram 15
Sangita Panchal
Histogram Bar
A graphical representation to
show the frequency of numerical
data.
A pictorial representation of data
to compare different category of
data.
Bars touch each other, hence
there are no spaces between
bars.
Bars do not touch each other,
hence there are spaces between
bars.
The width of bar may or may not
same (depends on bins)
The width of bar remain same.
CBSE Questions 16
Sangita Panchal
Fill in the blanks :
1. The command used to give a heading to a graph is _________
a. plt.show()
b. plt.plot()
c. plt.xlabel()
d. plt.title()
2. Using Python Matplotlib _________ can be used to count how
many values fall into each interval
a. line plot
b. bar graph
c. histogram
CBSE Questions 17
Sangita Panchal
Fill in the blanks :
1. The command used to give a heading to a graph is _________
a. plt.show()
b. plt.plot()
c. plt.xlabel()
d. plt.title()
2. Using Python Matplotlib _________ can be used to count how
many values fall into each interval
a. line plot
b. bar graph
c. histogram
plt.title()
histogram
CBSE Questions 18
Sangita Panchal
Rashmi wants to plot a bar graph for the department name on x
– axis and number of employees in each department on y-axis.
Complete the code to perform the following:
(i) To plot the bar graph in statement 1
(ii) To display the graph on screen in statement 2
import matplotlib as plt
x = [‘Marketing’, ‘Office’, ‘Manager’, ‘Development’]
y = [ 35, 29, 30, 25]
_______________________________ Statement 1
_______________________________ Statement 2
CBSE Questions 19
Sangita Panchal
Rashmi wants to plot a bar graph for the department name on x
– axis and number of employees in each department on y-axis.
Complete the code to perform the following:
(i) To plot the bar graph in statement 1
(ii) To display the graph on screen in statement 2
import matplotlib as plt
x = [‘Marketing’, ‘Office’, ‘Manager’, ‘Development’]
y = [ 35, 29, 30, 25]
_______________________________ Statement 1
_______________________________ Statement 2
plt.bar(x,y)
plt.show()
CBSE Questions 20
Sangita Panchal
Anamica wants to draw a line chart using a list of elements
named L. Complete the code to perform the following
operations:
(i) To plot a line chart using the list L
(ii) To give a y-axis label to the line chart as “List of Numbers”
import matplotlib.pyplot as plt
L = [10, 12, 15, 18, 25, 35, 50, 76, 89]
_______________________________ Statement 1
________________________________ Statement 2
plt.show()
CBSE Questions 21
Sangita Panchal
Anamica wants to draw a line chart using a list of elements
named L. Complete the code to perform the following
operations:
(i) To plot a line chart using the list L
(ii) To give a y-axis label to the line chart as “List of Numbers”
import matplotlib.pyplot as plt
L = [10, 12, 15, 18, 25, 35, 50, 76, 89]
_______________________________ Statement 1
________________________________ Statement 2
plt.show()
plt.plot(L)
plt.ylabel(“List of Numbers”)
CBSE Questions 22
Sangita Panchal
Write a code to plot the speed of a passenger train as shown in
the figure given below.
CBSE Questions 23
Sangita Panchal
Write a code to plot the speed of a passenger train as shown in
the figure given below.
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1, 5)
plt.plot(x, x*2.0, label='Normal')
plt.plot(x, x*3.0, label='Fast')
plt.plot(x, x/2.0, label='Slow')
plt.legend()
plt.show()
CBSE Questions 24
Sangita Panchal
Consider the following graph . Write the code to plot it.
CBSE Questions 25
Sangita Panchal
Consider the following graph . Write the code to plot it.
SOLUTION 1
import matplotlib.pyplot as plt
plt.plot([2,7],[1,6])
plt.show()
SOLUTION 2
import matplotlib.pyplot as plt
Y = [1,2,3,4,5,6]
X = [2,3,4,5,6,7]
plt.plot (X, Y)
CBSE Questions 26
Sangita Panchal
Draw the following bar graph representing the number of
students in each class.
CBSE Questions 27
Sangita Panchal
Draw the following bar graph representing the number of students in
each class.
import matplotlib.pyplot as plt
Classes = ['VII','VIII','IX','X']
Students = [40,45,35,44]
plt.bar(classes, students)
plt.show()
CBSE Questions 28
Sangita Panchal
Write a code to plot a bar chart to depict the pass
percentage of students in CBSE exams for the last four years
as shown below:
CBSE Questions 29
Sangita Panchal
Write a code to plot a bar chart to depict the pass
percentage of students in CBSE exams for the last four years
as shown below:
import matplotlib.pyplot as plt
objects= ["Year1","Year2","Year3","Year4"]
percentage=[82,83,85,90]
plt.bar(objects, percentage)
plt.ylabel("Pass Percentage")
plt.xlabel("Years")
plt.show()
CBSE Questions 30
Sangita Panchal
Mr. Vinay wants to plot line charts to compare the trend in the price of diesel and
petrol over the last few weeks from the following data in Python Lists. Help him
write the complete code by filling in the blanks :
(i) To plot the price of diesel in statement 1
(ii) To plot the price of petrol in statement 2
(iii) To give a suitable heading to the graph in statement 3
(iv) To display the legends in statement 4
(v) To display the graph in statement 5
import matplotlib.pyplot as plt
petrol = [ 80 , 82 , 82.50 , 81, 81.50 ]
diesel = [ 73 , 77 , 74 , 74.5 , 75.4 ]
_____________________ Statement 1
_____________________ Statement 2
_____________________ Statement 3
_____________________ Statement 4
_____________________ Statement 5
CBSE Questions 31
Sangita Panchal
Mr. Vinay wants to plot line charts to compare the trend in the price of diesel and
petrol over the last few weeks from the following data in Python Lists. Help him
write the complete code by filling in the blanks :
(i) To plot the price of diesel in statement 1
(ii) To plot the price of petrol in statement 2
(iii) To give a suitable heading to the graph in statement 3
(iv) To display the legends in statement 4
(v) To display the graph in statement 5
import matplotlib.pyplot as plt
petrol = [ 80 , 82 , 82.50 , 81, 81.50 ]
diesel = [ 73 , 77 , 74 , 74.5 , 75.4 ]
_____________________ Statement 1
_____________________ Statement 2
_____________________ Statement 3
_____________________ Statement 4
_____________________ Statement 5
plt.plot(diesel)
plt.plot(petrol)
plt.title(‘Price of Diesel vs petrol’)
plt.legend(‘Diesel’,’Petrol’)
plt.show()
CBSE Questions 32
Sangita Panchal
Mr. Vinay wants to plot line charts to compare the trend in the price of diesel and petrol over
the last few weeks from the following data in Python Lists. Help him write the complete code
by filling in the blanks :
Following is the data ( in hours ) of screen time spent on a device by sample students:
6,6,5,7,9,7,4,5,4,5,7,8,4,5,7,6,5,7,8,4,3,3,6,5.
The data is plotted to generate a histogram as follows:
Fill in the blanks to complete the code:
(i) To plot the histogram from the given data in Statement1
(ii) To save the figure as “Plot3.png” in Statement2
import matplotlib.pyplot as plt
hours =[6,6,5,7,9,7,4,5,4,5,7,8,4,5,7,6,5,7,8,4,3,3,6,5]
______________________ # Statement1
______________________ # Statement2
CBSE Questions 33
Sangita Panchal
Mr. Vinay wants to plot line charts to compare the trend in the price of diesel and petrol over
the last few weeks from the following data in Python Lists. Help him write the complete code
by filling in the blanks :
Following is the data ( in hours ) of screen time spent on a device by sample students:
6,6,5,7,9,7,4,5,4,5,7,8,4,5,7,6,5,7,8,4,3,3,6,5.
The data is plotted to generate a histogram as follows:
Fill in the blanks to complete the code:
(i) To plot the histogram from the given data in Statement1
(ii) To save the figure as “Plot3.png” in Statement2
import matplotlib.pyplot as plt
hours =[6,6,5,7,9,7,4,5,4,5,7,8,4,5,7,6,5,7,8,4,3,3,6,5]
______________________ # Statement1
______________________ # Statement2
plt.hist(hours)
plt.savefig(‘plot3.png’)
Subplots 34
Sangita Panchal
import matplotlib.pyplot as plt
fig,a = plt.subplots(2,2)
import numpy as np
x = np.arange(1,5)
y = [25,23,19,16]
y1 = [15,20,25,35]
fig.suptitle("Four Graphs")
a[0][0].plot(x,y,color = "g")
a[0][0].set_title('Line chart')
a[0][1].bar(x,y,color = "r")
a[0][1].set_title('Bar chart')
a[1][0].hist(y1,weights = [9,12,15,25],bins
=[10,20,30,40],color = "y",edgecolor = "b")
a[1][0].set_title('Histogram chart')
a[1][1].barh(x,y)
a[1][1].set_title('Horizontal Bar chart')
plt.show()
Data Visualization 2020_21

Weitere ähnliche Inhalte

Was ist angesagt?

Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arraysNeeru Mittal
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional arrayRajendran
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data ManipulationChu An
 
Multi-Dimensional Lists
Multi-Dimensional ListsMulti-Dimensional Lists
Multi-Dimensional Listsprimeteacher32
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in CSmit Parikh
 
Programs in array using SWIFT
Programs in array using SWIFTPrograms in array using SWIFT
Programs in array using SWIFTvikram mahendra
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheetGil Cohen
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updatedvrgokila
 
Python Pandas for Data Science cheatsheet
Python Pandas for Data Science cheatsheet Python Pandas for Data Science cheatsheet
Python Pandas for Data Science cheatsheet Dr. Volkan OBAN
 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Lucas Witold Adamus
 
Scala collection methods flatMap and flatten are more powerful than monadic f...
Scala collection methods flatMap and flatten are more powerful than monadic f...Scala collection methods flatMap and flatten are more powerful than monadic f...
Scala collection methods flatMap and flatten are more powerful than monadic f...Philip Schwarz
 

Was ist angesagt? (20)

Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
 
Array
ArrayArray
Array
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data Manipulation
 
Chapter2
Chapter2Chapter2
Chapter2
 
Multi-Dimensional Lists
Multi-Dimensional ListsMulti-Dimensional Lists
Multi-Dimensional Lists
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in C
 
Programs in array using SWIFT
Programs in array using SWIFTPrograms in array using SWIFT
Programs in array using SWIFT
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheet
 
R교육1
R교육1R교육1
R교육1
 
2D Array
2D Array 2D Array
2D Array
 
Data import-cheatsheet
Data import-cheatsheetData import-cheatsheet
Data import-cheatsheet
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
 
Data transformation-cheatsheet
Data transformation-cheatsheetData transformation-cheatsheet
Data transformation-cheatsheet
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
 
Python Pandas for Data Science cheatsheet
Python Pandas for Data Science cheatsheet Python Pandas for Data Science cheatsheet
Python Pandas for Data Science cheatsheet
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?
 
Scala collection methods flatMap and flatten are more powerful than monadic f...
Scala collection methods flatMap and flatten are more powerful than monadic f...Scala collection methods flatMap and flatten are more powerful than monadic f...
Scala collection methods flatMap and flatten are more powerful than monadic f...
 

Ähnlich wie Data Visualization 2020_21

16. Data VIsualization using PyPlot.pdf
16. Data VIsualization using PyPlot.pdf16. Data VIsualization using PyPlot.pdf
16. Data VIsualization using PyPlot.pdfRrCreations5
 
UNit-III. part 2.pdf
UNit-III. part 2.pdfUNit-III. part 2.pdf
UNit-III. part 2.pdfMastiCreation
 
Visualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxVisualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxSharmilaMore5
 
Data Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix MultiplicationData Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix Multiplicationbabuk110
 
Fundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLABFundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLABAli Ghanbarzadeh
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkTUOS-Sam
 
Introduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordIntroduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordLakshmi Sarvani Videla
 
PYTHON-Chapter 4-Plotting and Data Science PyLab - MAULIK BORSANIYA
PYTHON-Chapter 4-Plotting and Data Science  PyLab - MAULIK BORSANIYAPYTHON-Chapter 4-Plotting and Data Science  PyLab - MAULIK BORSANIYA
PYTHON-Chapter 4-Plotting and Data Science PyLab - MAULIK BORSANIYAMaulik Borsaniya
 
Data visualization using py plot part i
Data visualization using py plot part iData visualization using py plot part i
Data visualization using py plot part iTutorialAICSIP
 
Presentation: Plotting Systems in R
Presentation: Plotting Systems in RPresentation: Plotting Systems in R
Presentation: Plotting Systems in RIlya Zhbannikov
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxagnesdcarey33086
 
Matlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingMatlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingDr. Manjunatha. P
 
Chart and graphs in R programming language
Chart and graphs in R programming language Chart and graphs in R programming language
Chart and graphs in R programming language CHANDAN KUMAR
 
Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Philip Schwarz
 

Ähnlich wie Data Visualization 2020_21 (20)

12-IP.pdf
12-IP.pdf12-IP.pdf
12-IP.pdf
 
MatplotLib.pptx
MatplotLib.pptxMatplotLib.pptx
MatplotLib.pptx
 
16. Data VIsualization using PyPlot.pdf
16. Data VIsualization using PyPlot.pdf16. Data VIsualization using PyPlot.pdf
16. Data VIsualization using PyPlot.pdf
 
Matplotlib
MatplotlibMatplotlib
Matplotlib
 
UNit-III. part 2.pdf
UNit-III. part 2.pdfUNit-III. part 2.pdf
UNit-III. part 2.pdf
 
Visualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxVisualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptx
 
Data Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix MultiplicationData Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix Multiplication
 
Fundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLABFundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLAB
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & Coursework
 
Introduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordIntroduction to Data Science With R Lab Record
Introduction to Data Science With R Lab Record
 
Mmc manual
Mmc manualMmc manual
Mmc manual
 
Python for Data Science
Python for Data SciencePython for Data Science
Python for Data Science
 
PYTHON-Chapter 4-Plotting and Data Science PyLab - MAULIK BORSANIYA
PYTHON-Chapter 4-Plotting and Data Science  PyLab - MAULIK BORSANIYAPYTHON-Chapter 4-Plotting and Data Science  PyLab - MAULIK BORSANIYA
PYTHON-Chapter 4-Plotting and Data Science PyLab - MAULIK BORSANIYA
 
Data visualization using py plot part i
Data visualization using py plot part iData visualization using py plot part i
Data visualization using py plot part i
 
Matlab1
Matlab1Matlab1
Matlab1
 
Presentation: Plotting Systems in R
Presentation: Plotting Systems in RPresentation: Plotting Systems in R
Presentation: Plotting Systems in R
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
 
Matlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingMatlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processing
 
Chart and graphs in R programming language
Chart and graphs in R programming language Chart and graphs in R programming language
Chart and graphs in R programming language
 
Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1
 

Kürzlich hochgeladen

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsRommel Regala
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxRosabel UA
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 

Kürzlich hochgeladen (20)

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World Politics
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 

Data Visualization 2020_21

  • 2. Data Visualization  Purpose of plotting;  drawing and saving following types of plots using matplotlib – line plot, bar graph, histogram, pie chart, frequency polygon, box plot and scatter plot.  Customizing plots: color, style (dashed, dotted), width; adding label, title, and legend in plots. 1 Sangita Panchal
  • 3. Purpose of Plotting 2 Sangita Panchal  One of the most popular uses for Python is data analysis. Data scientists want a way to visualize their data to get a better grasp of the data, and to convey their results to someone.  Matplotlib is a Python library used for plotting. It is used to create 2d Plots and graphs easily and control font properties, line controls, formatting axes, etc. through Python script.
  • 4. Line Chart 3 Sangita Panchal import matplotlib.pyplot as plt plt.plot([1,2,3],[4,5,1]) plt.show() import matplotlib.pyplot as plt plt.plot([4,5,1]) plt.show()
  • 5. Line Chart 3 Sangita Panchal import matplotlib.pyplot as plt plt.plot([‘A’,’B’,’C’],[4,5,1]) plt.show() import matplotlib.pyplot as plt plt.plot([1,5],[2,6]) plt.show()
  • 6. Line Chart Try all the commands 4 Sangita Panchal import matplotlib.pyplot as plt x = ['A1','B1','C1'] y = [31,27,40] x1 = ['A1','B1','C1','D1'] y1 = [12,20,19,17] plt.plot(x,y,label = "Sr. School") plt.plot(x1,y1,label = "Jr.School") plt.title("Bus Info") plt.ylabel("No. of Students") plt.xlabel("Bus No.") plt.legend() plt.savefig("businfo") plt.show() Title xlabel ylabel Legend
  • 7. Line Chart 5 Sangita Panchal Save the figure plt.savefig(“linechart.pdf”) # saves in the current directory plt.savefig(“c:datamultibar.pdf”) # saves in the given path plt.savefig(“c:datamultibar.png”) # saves in the given path in .png format
  • 8. Bar Chart 9 Sangita Panchal import matplotlib.pyplot as plt # Students in each section x = ['A','B','C','D','E'] y = [31,27,40,43,45] plt.bar(x,y,label = "No.of students") plt.title("Section wise number of students") plt.ylabel("No. of Students") plt.xlabel("Section") plt.legend() plt.show()
  • 9. Bar Chart Horizontal 10 Sangita Panchal import matplotlib.pyplot as plt # Students in each section x = ['A','B','C','D','E'] y = [31,27,40,43,45] plt.barh(x,y,label = "No.of students") plt.title("Section wise number of students") plt.ylabel("No. of Students") plt.xlabel("Section") plt.legend() plt.show()
  • 10. Bar Chart Stacked 11 Sangita Panchal import matplotlib.pyplot as plt # Number of students in each bus x = [‘A’, ‘B’, ‘C’, ‘D’] y = [31,27,40,32] y1 = [12,20,19,17] plt.bar(x,y,label = "Sr. School") plt.bar(x,y1,label = "Jr.School") plt.title("Bus Info") plt.ylabel("No. of Students") plt.xlabel("Bus No.") plt.legend() plt.show()
  • 11. Bar Chart – Multiple 12 Sangita Panchal import matplotlib.pyplot as plt import numpy as np # Number of students in each bus x = np.arange(1,5) y = [31,27,40,32] y1 = [12,20,19,17] plt.bar(x+0,y,label = "Sr. School",width = 0.4) plt.bar(x+0.4,y1,label = "Jr.School",width = 0.4) plt.title("Bus Info") plt.ylabel("No. of Students") plt.xlabel("Bus No.") plt.legend() plt.show()
  • 12. Histogram 13 Sangita Panchal import matplotlib.pyplot as plt import numpy as np # Marks obtained by 50 students x = [5,15,20,25,35,45,55] y = np.arange(0,61,10) w = [2,3,8,9,12,6,10] plt.hist(x,bins = y, weights = w, label = "Marks Obtained") plt.title("Histogram") plt.ylabel("Marks Range") plt.xlabel("No. of Students") plt.legend() plt.show()
  • 13. Histogram 13 Sangita Panchal import matplotlib.pyplot as plt import numpy as np # Marks obtained by 50 students x = [5,15,20,25,35,45,55,70,84,90,93] y = [0,33,45,60,75,90,100] w = [2,3,8,9,12,6,10,5,8,12,7] plt.hist(x,bins = y, weights = w, label = "Marks Obtained", edgecolor = "yellow") plt.title("Histogram") plt.ylabel("Marks Range") plt.xlabel("No. of Students") plt.legend() plt.show()
  • 14. Difference between Bar graph and Histogram 13 Sangita Panchal
  • 15. Difference between Bar graph and Histogram 14 Sangita Panchal Histogram Bar Histogram is defined as a type of bar chart that to show the frequency distribution of continuous data. It indicates the number of observations which lie in- between the range of values, known as class or bin. Take the observations and split them into logical series of intervals called bins. X-axis indicates, independent variables i.e. bins Y-axis represents dependent variables i.e. occurrences. Rectangle blocks i.e. bars are shown on the x-axis, whose area depends on the bins. A bar graph is a chart that represents the comparison between categories of data. It displays grouped data by way of parallel rectangular bars of equal width but varying the length. Each rectangular block indicates specific category and the length of the bars depends on the values they hold. The bars do not touch each other. Bar diagram can be horizontal or vertical, where a horizontal bar graph is used to display data varying over space whereas the vertical bar graph represents time series data. It contains two axis, where one axis represents the categories and the other axis shows the discrete values of the data.
  • 16. Difference between Bar graph and Histogram 15 Sangita Panchal Histogram Bar A graphical representation to show the frequency of numerical data. A pictorial representation of data to compare different category of data. Bars touch each other, hence there are no spaces between bars. Bars do not touch each other, hence there are spaces between bars. The width of bar may or may not same (depends on bins) The width of bar remain same.
  • 17. CBSE Questions 16 Sangita Panchal Fill in the blanks : 1. The command used to give a heading to a graph is _________ a. plt.show() b. plt.plot() c. plt.xlabel() d. plt.title() 2. Using Python Matplotlib _________ can be used to count how many values fall into each interval a. line plot b. bar graph c. histogram
  • 18. CBSE Questions 17 Sangita Panchal Fill in the blanks : 1. The command used to give a heading to a graph is _________ a. plt.show() b. plt.plot() c. plt.xlabel() d. plt.title() 2. Using Python Matplotlib _________ can be used to count how many values fall into each interval a. line plot b. bar graph c. histogram plt.title() histogram
  • 19. CBSE Questions 18 Sangita Panchal Rashmi wants to plot a bar graph for the department name on x – axis and number of employees in each department on y-axis. Complete the code to perform the following: (i) To plot the bar graph in statement 1 (ii) To display the graph on screen in statement 2 import matplotlib as plt x = [‘Marketing’, ‘Office’, ‘Manager’, ‘Development’] y = [ 35, 29, 30, 25] _______________________________ Statement 1 _______________________________ Statement 2
  • 20. CBSE Questions 19 Sangita Panchal Rashmi wants to plot a bar graph for the department name on x – axis and number of employees in each department on y-axis. Complete the code to perform the following: (i) To plot the bar graph in statement 1 (ii) To display the graph on screen in statement 2 import matplotlib as plt x = [‘Marketing’, ‘Office’, ‘Manager’, ‘Development’] y = [ 35, 29, 30, 25] _______________________________ Statement 1 _______________________________ Statement 2 plt.bar(x,y) plt.show()
  • 21. CBSE Questions 20 Sangita Panchal Anamica wants to draw a line chart using a list of elements named L. Complete the code to perform the following operations: (i) To plot a line chart using the list L (ii) To give a y-axis label to the line chart as “List of Numbers” import matplotlib.pyplot as plt L = [10, 12, 15, 18, 25, 35, 50, 76, 89] _______________________________ Statement 1 ________________________________ Statement 2 plt.show()
  • 22. CBSE Questions 21 Sangita Panchal Anamica wants to draw a line chart using a list of elements named L. Complete the code to perform the following operations: (i) To plot a line chart using the list L (ii) To give a y-axis label to the line chart as “List of Numbers” import matplotlib.pyplot as plt L = [10, 12, 15, 18, 25, 35, 50, 76, 89] _______________________________ Statement 1 ________________________________ Statement 2 plt.show() plt.plot(L) plt.ylabel(“List of Numbers”)
  • 23. CBSE Questions 22 Sangita Panchal Write a code to plot the speed of a passenger train as shown in the figure given below.
  • 24. CBSE Questions 23 Sangita Panchal Write a code to plot the speed of a passenger train as shown in the figure given below. import matplotlib.pyplot as plt import numpy as np x = np.arange(1, 5) plt.plot(x, x*2.0, label='Normal') plt.plot(x, x*3.0, label='Fast') plt.plot(x, x/2.0, label='Slow') plt.legend() plt.show()
  • 25. CBSE Questions 24 Sangita Panchal Consider the following graph . Write the code to plot it.
  • 26. CBSE Questions 25 Sangita Panchal Consider the following graph . Write the code to plot it. SOLUTION 1 import matplotlib.pyplot as plt plt.plot([2,7],[1,6]) plt.show() SOLUTION 2 import matplotlib.pyplot as plt Y = [1,2,3,4,5,6] X = [2,3,4,5,6,7] plt.plot (X, Y)
  • 27. CBSE Questions 26 Sangita Panchal Draw the following bar graph representing the number of students in each class.
  • 28. CBSE Questions 27 Sangita Panchal Draw the following bar graph representing the number of students in each class. import matplotlib.pyplot as plt Classes = ['VII','VIII','IX','X'] Students = [40,45,35,44] plt.bar(classes, students) plt.show()
  • 29. CBSE Questions 28 Sangita Panchal Write a code to plot a bar chart to depict the pass percentage of students in CBSE exams for the last four years as shown below:
  • 30. CBSE Questions 29 Sangita Panchal Write a code to plot a bar chart to depict the pass percentage of students in CBSE exams for the last four years as shown below: import matplotlib.pyplot as plt objects= ["Year1","Year2","Year3","Year4"] percentage=[82,83,85,90] plt.bar(objects, percentage) plt.ylabel("Pass Percentage") plt.xlabel("Years") plt.show()
  • 31. CBSE Questions 30 Sangita Panchal Mr. Vinay wants to plot line charts to compare the trend in the price of diesel and petrol over the last few weeks from the following data in Python Lists. Help him write the complete code by filling in the blanks : (i) To plot the price of diesel in statement 1 (ii) To plot the price of petrol in statement 2 (iii) To give a suitable heading to the graph in statement 3 (iv) To display the legends in statement 4 (v) To display the graph in statement 5 import matplotlib.pyplot as plt petrol = [ 80 , 82 , 82.50 , 81, 81.50 ] diesel = [ 73 , 77 , 74 , 74.5 , 75.4 ] _____________________ Statement 1 _____________________ Statement 2 _____________________ Statement 3 _____________________ Statement 4 _____________________ Statement 5
  • 32. CBSE Questions 31 Sangita Panchal Mr. Vinay wants to plot line charts to compare the trend in the price of diesel and petrol over the last few weeks from the following data in Python Lists. Help him write the complete code by filling in the blanks : (i) To plot the price of diesel in statement 1 (ii) To plot the price of petrol in statement 2 (iii) To give a suitable heading to the graph in statement 3 (iv) To display the legends in statement 4 (v) To display the graph in statement 5 import matplotlib.pyplot as plt petrol = [ 80 , 82 , 82.50 , 81, 81.50 ] diesel = [ 73 , 77 , 74 , 74.5 , 75.4 ] _____________________ Statement 1 _____________________ Statement 2 _____________________ Statement 3 _____________________ Statement 4 _____________________ Statement 5 plt.plot(diesel) plt.plot(petrol) plt.title(‘Price of Diesel vs petrol’) plt.legend(‘Diesel’,’Petrol’) plt.show()
  • 33. CBSE Questions 32 Sangita Panchal Mr. Vinay wants to plot line charts to compare the trend in the price of diesel and petrol over the last few weeks from the following data in Python Lists. Help him write the complete code by filling in the blanks : Following is the data ( in hours ) of screen time spent on a device by sample students: 6,6,5,7,9,7,4,5,4,5,7,8,4,5,7,6,5,7,8,4,3,3,6,5. The data is plotted to generate a histogram as follows: Fill in the blanks to complete the code: (i) To plot the histogram from the given data in Statement1 (ii) To save the figure as “Plot3.png” in Statement2 import matplotlib.pyplot as plt hours =[6,6,5,7,9,7,4,5,4,5,7,8,4,5,7,6,5,7,8,4,3,3,6,5] ______________________ # Statement1 ______________________ # Statement2
  • 34. CBSE Questions 33 Sangita Panchal Mr. Vinay wants to plot line charts to compare the trend in the price of diesel and petrol over the last few weeks from the following data in Python Lists. Help him write the complete code by filling in the blanks : Following is the data ( in hours ) of screen time spent on a device by sample students: 6,6,5,7,9,7,4,5,4,5,7,8,4,5,7,6,5,7,8,4,3,3,6,5. The data is plotted to generate a histogram as follows: Fill in the blanks to complete the code: (i) To plot the histogram from the given data in Statement1 (ii) To save the figure as “Plot3.png” in Statement2 import matplotlib.pyplot as plt hours =[6,6,5,7,9,7,4,5,4,5,7,8,4,5,7,6,5,7,8,4,3,3,6,5] ______________________ # Statement1 ______________________ # Statement2 plt.hist(hours) plt.savefig(‘plot3.png’)
  • 35. Subplots 34 Sangita Panchal import matplotlib.pyplot as plt fig,a = plt.subplots(2,2) import numpy as np x = np.arange(1,5) y = [25,23,19,16] y1 = [15,20,25,35] fig.suptitle("Four Graphs") a[0][0].plot(x,y,color = "g") a[0][0].set_title('Line chart') a[0][1].bar(x,y,color = "r") a[0][1].set_title('Bar chart') a[1][0].hist(y1,weights = [9,12,15,25],bins =[10,20,30,40],color = "y",edgecolor = "b") a[1][0].set_title('Histogram chart') a[1][1].barh(x,y) a[1][1].set_title('Horizontal Bar chart') plt.show()