SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
1
Data Visualization using PyPlot
Read the following quotes:
“Visualization gives you answers to questions you didn’t know you had.” - Ben Schneiderman
“An editorial approach to visualization design requires us to take responsibility to filter out the noise from the
signals, identifying the most valuable, most striking or most relevant dimensions of the subject matter in
question.” - Andy Kirk
“Data visualization doesn’t live in an ethereal dimension, separated from the data. When there’s a large number
of pie-charts in a report or a presentation, there is something wrong in the organization, and it’s not the pie. A
pie chart is a potential symptom of lack of data analysis skills that have to be resolved.” – Jorge Camoes
Quotes Source
Pictures playing an important role in representing data. As we all are aware that pictures giving a more and
more clear understanding of any kind of data or complex problems. Some of the images help to understand the
structure or patterns of data flow and execution.
Before going ahead, If you missed the notes on data frames check out our main page of Informatics
Practices class XII portion.
In this post, we will discuss the following topics:
Basic components of Graph
A graph has the following basic components:
1. Figure or chart area: The entire area covered by the graph is known as a figure. It can be also
considered as a canvas or chart area also.
2. Axis: These are the number of lines generated on the plot. Basically, there are two axis X and Y-axis.
3. Artist: The components like text objects, Line 2D objects, collection objects, etc.
4. Titles: There are few titles involved with your charts such as Chart Title, Axis title, etc.
5. Legends: Legends are the information that represents data with lines or dots.
Matplolib
Python supports a variety of packages to handle data. Matplotlib is also one of the most important packages out
of them. It is a low-level library integrated with Matlab like interface offers few lines of code and draw graphs
or charts. It has modules such as pyplot to draw and create graphs.
Steps how to use Matplotlib
Step 1 Installation of matplotlib
Install matplotlib by following these simple steps:
Step 1: Open cmd from the start menu
Step 2: Type pip install matplotlib
2
Step 2 import module
Import matplotlib.pylot using import command in the following two ways:
1. Without instance
import matplotlib.pyplot
2. With instance
import matplotlib.pyplot as mpp
Step 3 Choose desired plot type (graph type)
In this step, select your desired chart type for plotting. For example, line chart
Step 4 Give proper labels to axis, categories
A graph is made up of two-axis i.e. X and Y-axis. In this step label them as per the need as well as apply proper
labels for categories also.
Step 5 Add data points
The next point is to add data points. Data points depict the point on the plot at a particular place.
Step 6 Add more functionality like colors, sizes etc
To make your graphs more effective and informative use different colors and different sizes.
The common method used to plot a chart is plot().
The Pyplot package provides an interface to plot the graph automatically as per the requirements. You just need
to provide accurate values for axes, categories, labels, title, legend, and data points.
Matplotlib provides the following types of graphs in python:
 Line plot
 Bar graph
 Histogram
 Pie chart
 Scatter chart
3
Creating a Line chart or Plotting lines
To create a line chart following functions are used:
 plot(x,y,color,others): Draw lines as per specified lines
 xlabel("label"): For label to x-axis
 ylabel("label"): For label to y-axis
 title("Title"): For title of the axes
 legend(): For displaying legends
 show() : Display the graph
Now observe the following code:
import matplotlib.pyplot as mpp
mpp.plot(['English','Maths','Hindi'],[88,90,94],'Red')
mpp.xlabel('Subjects')
mpp.ylabel('Marks')
mpp.title('Progress Report Chart')
mpp.show()
Output:
Line plot in Python 3.8.3
4
In the above code, 3 subject marks are plotted on the figure. The navigation toolbar helps to navigate through
the graph. Now observe the following code for plotting multiple lines on the graph.
import matplotlib.pyplot as mpp
o=[5,10,15,20]
r_india=[30,80,120,200]
mpp.plot(o,r_india,'Red')
r_aust=[25,85,100,186]
mpp.plot(o,r_aust,'Yellow')
mpp.xlabel('Runs')
mpp.ylabel('Overs')
mpp.title('Match Summary')
mpp.show()
Output:
Multiline chart using Python 3.8.3
So now you understand how to plot lines on the figure. You can change the color using abbreviations and line
style by using linestyle parameter also. Just do the following changes in above-given code and see the output:
mpp.plot(o,r_india,'m',linestyle=':')
mpp.plot(o,r_aust,'y',linestyle='-.')
5
Bar Graph
The bar graph represents data in horizontal or vertical bars. The bar() function is used to create bar graph. It is
most commonly used for 2D data representation. Just have a look at the following code:
import matplotlib.pyplot as mpp
overs=[5,10,15,20]
runs=[30,80,120,200]
mpp.bar(runs,overs,width=30, label='Runs',color='r')
mpp.xlabel('Runs')
mpp.ylabel('Overs')
mpp.title('Match Summary')
mpp.legend()
mpp.show()
Output:
Bar Graph in python 3.8.3

More Related Content

PPTX
EX-6-Implement Matrix Multiplication with Hadoop Map Reduce.pptx
PDF
Data visualization in Python
PPTX
Python Scipy Numpy
PPTX
Scikit Learn intro
PPTX
Knapsack Problem
ODP
Data Analysis in Python
EX-6-Implement Matrix Multiplication with Hadoop Map Reduce.pptx
Data visualization in Python
Python Scipy Numpy
Scikit Learn intro
Knapsack Problem
Data Analysis in Python

What's hot (20)

PDF
Python NumPy Tutorial | NumPy Array | Edureka
PPTX
Apriori algorithm
PPTX
PPT on Data Science Using Python
PPT
EULER AND FERMAT THEOREM
PPTX
ID3 ALGORITHM
PDF
The Future of Data Science
PDF
Introduction to XGBoost
PPT
01 Data Mining: Concepts and Techniques, 2nd ed.
PPT
0/1 knapsack
PPT
Data encryption standard
PPTX
Lect6 Association rule & Apriori algorithm
PPTX
Asymptotic notations
PDF
Tutorial on Web Scraping in Python
PPTX
Running of nist test
PDF
Little o and little omega
PPTX
PDF
Hackolade Tutorial - part 2 - Overview of JSON and JSON schema
PDF
Pagerank and hits
PPTX
Message digest 5
PPT
Secure Socket Layer
Python NumPy Tutorial | NumPy Array | Edureka
Apriori algorithm
PPT on Data Science Using Python
EULER AND FERMAT THEOREM
ID3 ALGORITHM
The Future of Data Science
Introduction to XGBoost
01 Data Mining: Concepts and Techniques, 2nd ed.
0/1 knapsack
Data encryption standard
Lect6 Association rule & Apriori algorithm
Asymptotic notations
Tutorial on Web Scraping in Python
Running of nist test
Little o and little omega
Hackolade Tutorial - part 2 - Overview of JSON and JSON schema
Pagerank and hits
Message digest 5
Secure Socket Layer
Ad

Similar to Data visualization using py plot part i (20)

PDF
12-IP.pdf
PPTX
Visualization and Matplotlib using Python.pptx
PPTX
data analytics and visualization CO4_18_Data Types for Plotting.pptx
PPTX
PYTHON-Chapter 4-Plotting and Data Science PyLab - MAULIK BORSANIYA
PPTX
UNIT_4_data visualization.pptx
PPTX
Matplotlib yayyyyyyyyyyyyyin Python.pptx
PPTX
Unit3-v1-Plotting and Visualization.pptx
PPTX
Lecture 1 Pandas Basics.pptx machine learning
PPTX
Python for Data Science
PPTX
Introduction to Pylab and Matploitlib.
PPTX
Introduction to matplotlib
PDF
Image processing using matlab
PPTX
Session 04 communicating results
PPTX
Session 04 communicating results
PDF
Matlab dip
PPTX
UNIT-5-II IT-DATA VISUALIZATION TECHNIQUES
PDF
Unlocking Insights Data Analysis Visualization
PPTX
2. Python Library Matplotlibmmmmmmmm.pptx
PDF
Astronomy_python_data_Analysis_made_easy.pdf
PPTX
Python Pyplot Class XII
12-IP.pdf
Visualization and Matplotlib using Python.pptx
data analytics and visualization CO4_18_Data Types for Plotting.pptx
PYTHON-Chapter 4-Plotting and Data Science PyLab - MAULIK BORSANIYA
UNIT_4_data visualization.pptx
Matplotlib yayyyyyyyyyyyyyin Python.pptx
Unit3-v1-Plotting and Visualization.pptx
Lecture 1 Pandas Basics.pptx machine learning
Python for Data Science
Introduction to Pylab and Matploitlib.
Introduction to matplotlib
Image processing using matlab
Session 04 communicating results
Session 04 communicating results
Matlab dip
UNIT-5-II IT-DATA VISUALIZATION TECHNIQUES
Unlocking Insights Data Analysis Visualization
2. Python Library Matplotlibmmmmmmmm.pptx
Astronomy_python_data_Analysis_made_easy.pdf
Python Pyplot Class XII
Ad

Recently uploaded (20)

PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Basic Mud Logging Guide for educational purpose
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
Insiders guide to clinical Medicine.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
RMMM.pdf make it easy to upload and study
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Cell Types and Its function , kingdom of life
PDF
Complications of Minimal Access Surgery at WLH
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Basic Mud Logging Guide for educational purpose
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Insiders guide to clinical Medicine.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
RMMM.pdf make it easy to upload and study
PPH.pptx obstetrics and gynecology in nursing
Microbial diseases, their pathogenesis and prophylaxis
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Anesthesia in Laparoscopic Surgery in India
human mycosis Human fungal infections are called human mycosis..pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
Cell Types and Its function , kingdom of life
Complications of Minimal Access Surgery at WLH
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Final Presentation General Medicine 03-08-2024.pptx
Supply Chain Operations Speaking Notes -ICLT Program

Data visualization using py plot part i

  • 1. 1 Data Visualization using PyPlot Read the following quotes: “Visualization gives you answers to questions you didn’t know you had.” - Ben Schneiderman “An editorial approach to visualization design requires us to take responsibility to filter out the noise from the signals, identifying the most valuable, most striking or most relevant dimensions of the subject matter in question.” - Andy Kirk “Data visualization doesn’t live in an ethereal dimension, separated from the data. When there’s a large number of pie-charts in a report or a presentation, there is something wrong in the organization, and it’s not the pie. A pie chart is a potential symptom of lack of data analysis skills that have to be resolved.” – Jorge Camoes Quotes Source Pictures playing an important role in representing data. As we all are aware that pictures giving a more and more clear understanding of any kind of data or complex problems. Some of the images help to understand the structure or patterns of data flow and execution. Before going ahead, If you missed the notes on data frames check out our main page of Informatics Practices class XII portion. In this post, we will discuss the following topics: Basic components of Graph A graph has the following basic components: 1. Figure or chart area: The entire area covered by the graph is known as a figure. It can be also considered as a canvas or chart area also. 2. Axis: These are the number of lines generated on the plot. Basically, there are two axis X and Y-axis. 3. Artist: The components like text objects, Line 2D objects, collection objects, etc. 4. Titles: There are few titles involved with your charts such as Chart Title, Axis title, etc. 5. Legends: Legends are the information that represents data with lines or dots. Matplolib Python supports a variety of packages to handle data. Matplotlib is also one of the most important packages out of them. It is a low-level library integrated with Matlab like interface offers few lines of code and draw graphs or charts. It has modules such as pyplot to draw and create graphs. Steps how to use Matplotlib Step 1 Installation of matplotlib Install matplotlib by following these simple steps: Step 1: Open cmd from the start menu Step 2: Type pip install matplotlib
  • 2. 2 Step 2 import module Import matplotlib.pylot using import command in the following two ways: 1. Without instance import matplotlib.pyplot 2. With instance import matplotlib.pyplot as mpp Step 3 Choose desired plot type (graph type) In this step, select your desired chart type for plotting. For example, line chart Step 4 Give proper labels to axis, categories A graph is made up of two-axis i.e. X and Y-axis. In this step label them as per the need as well as apply proper labels for categories also. Step 5 Add data points The next point is to add data points. Data points depict the point on the plot at a particular place. Step 6 Add more functionality like colors, sizes etc To make your graphs more effective and informative use different colors and different sizes. The common method used to plot a chart is plot(). The Pyplot package provides an interface to plot the graph automatically as per the requirements. You just need to provide accurate values for axes, categories, labels, title, legend, and data points. Matplotlib provides the following types of graphs in python:  Line plot  Bar graph  Histogram  Pie chart  Scatter chart
  • 3. 3 Creating a Line chart or Plotting lines To create a line chart following functions are used:  plot(x,y,color,others): Draw lines as per specified lines  xlabel("label"): For label to x-axis  ylabel("label"): For label to y-axis  title("Title"): For title of the axes  legend(): For displaying legends  show() : Display the graph Now observe the following code: import matplotlib.pyplot as mpp mpp.plot(['English','Maths','Hindi'],[88,90,94],'Red') mpp.xlabel('Subjects') mpp.ylabel('Marks') mpp.title('Progress Report Chart') mpp.show() Output: Line plot in Python 3.8.3
  • 4. 4 In the above code, 3 subject marks are plotted on the figure. The navigation toolbar helps to navigate through the graph. Now observe the following code for plotting multiple lines on the graph. import matplotlib.pyplot as mpp o=[5,10,15,20] r_india=[30,80,120,200] mpp.plot(o,r_india,'Red') r_aust=[25,85,100,186] mpp.plot(o,r_aust,'Yellow') mpp.xlabel('Runs') mpp.ylabel('Overs') mpp.title('Match Summary') mpp.show() Output: Multiline chart using Python 3.8.3 So now you understand how to plot lines on the figure. You can change the color using abbreviations and line style by using linestyle parameter also. Just do the following changes in above-given code and see the output: mpp.plot(o,r_india,'m',linestyle=':') mpp.plot(o,r_aust,'y',linestyle='-.')
  • 5. 5 Bar Graph The bar graph represents data in horizontal or vertical bars. The bar() function is used to create bar graph. It is most commonly used for 2D data representation. Just have a look at the following code: import matplotlib.pyplot as mpp overs=[5,10,15,20] runs=[30,80,120,200] mpp.bar(runs,overs,width=30, label='Runs',color='r') mpp.xlabel('Runs') mpp.ylabel('Overs') mpp.title('Match Summary') mpp.legend() mpp.show() Output: Bar Graph in python 3.8.3