SlideShare a Scribd company logo
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

More Related Content

What's hot

Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
Neeru Mittal
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
Golden Julie Jesus
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
Rajendran
 
Array
ArrayArray
Array
Anil Dutt
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data Manipulation
Chu An
 
Multi-Dimensional Lists
Multi-Dimensional ListsMulti-Dimensional Lists
Multi-Dimensional Lists
primeteacher32
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in C
Smit Parikh
 
Programs in array using SWIFT
Programs in array using SWIFTPrograms in array using SWIFT
Programs in array using SWIFT
vikram mahendra
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheet
Gil Cohen
 
2D Array
2D Array 2D Array
2D Array
Ehatsham Riaz
 
Data import-cheatsheet
Data import-cheatsheetData import-cheatsheet
Data import-cheatsheet
Dieudonne Nahigombeye
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
vrgokila
 
Data transformation-cheatsheet
Data transformation-cheatsheetData transformation-cheatsheet
Data transformation-cheatsheet
Dieudonne Nahigombeye
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
Ashim Lamichhane
 
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
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
Shubham Sharma
 
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
 

What's hot (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...
 

Similar to Data Visualization 2020_21

12-IP.pdf
12-IP.pdf12-IP.pdf
12-IP.pdf
kajalkhorwal106
 
MatplotLib.pptx
MatplotLib.pptxMatplotLib.pptx
MatplotLib.pptx
Paras Intotech
 
16. Data VIsualization using PyPlot.pdf
16. Data VIsualization using PyPlot.pdf16. Data VIsualization using PyPlot.pdf
16. Data VIsualization using PyPlot.pdf
RrCreations5
 
Matplotlib
MatplotlibMatplotlib
Matplotlib
Amir Shokri
 
UNit-III. part 2.pdf
UNit-III. part 2.pdfUNit-III. part 2.pdf
UNit-III. part 2.pdf
MastiCreation
 
Visualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxVisualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptx
SharmilaMore5
 
Data Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix MultiplicationData Structure & Algorithms - Matrix Multiplication
Data Structure & Algorithms - Matrix Multiplication
babuk110
 
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
Ali Ghanbarzadeh
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkTUOS-Sam
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
sumitt6_25730773
 
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
Lakshmi Sarvani Videla
 
Mmc manual
Mmc manualMmc manual
Mmc manual
Urvi Surat
 
Python for Data Science
Python for Data SciencePython for Data Science
Python for Data Science
Panimalar Engineering College
 
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
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
TutorialAICSIP
 
Presentation: Plotting Systems in R
Presentation: Plotting Systems in RPresentation: Plotting Systems in R
Presentation: Plotting Systems in R
Ilya 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).docx
agnesdcarey33086
 
Matlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingMatlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processing
Dr. 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
 

Similar to 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 Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
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
 

Recently uploaded

The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 

Recently uploaded (20)

The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 

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()