SlideShare a Scribd company logo
1 of 45
Download to read offline
Plotting using Matplot Lib
Data visualization basically refers to the graphical or visual
representation of information and data using charts, graphs, maps etc.
pyplot is an interface, which exists in matplotlib library.
To draw the lines, charts etc. first of all we have to install matplotlib library in our
computer and import it in the python program.
matplotlib is a package which is used to draw 2-D graphics.
Installing the matplotlib :
Step-1: Download the wheel package of matplotlib. To download go to
the following url:
https://pypi.org/project/matplotlib/#files
Step-2: Now install it using following commands on command prompt:
python –m pip install –U pip
python –m pip install –U matplotlib
COMMONLY USED CHART TYPES:
• Line Chart
• Bar Chart
• Pie Chart
Line Chart
– A line chart displays information as a series of data points
called “markers”.
– import the matplotlib library and pyplot interface.
– pyplot interface has plot( ) function to draw a line.
– To set the lables for x-axis and y-axis, xlabel( ) and ylabel( )
functions are used.
– Use show( ) function to display the line.
Line Graph
import matplotlib.pyplot as mat
x=[1,2,3]
y=[5,7,4]
mat.plot(x,y,label='First')
mat.xlabel('Cost')
mat.ylabel('Speed')
mat.title('Analysis Graph')
mat.legend()
mat.show()
Formatting the line chart:
Line : Change the line color, width and style
Marker : Change the marker Type, size and color
Change the line color, width and style:
Line color:
Syntax:
matplotlib.pyplot.plot(data1, data2, color-code)
Example:
matplotlib.pyplot.plot(x, y, ‘r’) #’r’ is color code for red
colour
color Code
Red ‘r’
Green ‘g’
Blue ‘b’
Yellow ‘y’
Magenta ‘m’
Black ‘k’
Cyan ‘c’
White ‘w’
Line width:
Syntax:
matplotlib.pyplot.plot(data1, data2, linewidth=value)
Example:
matplotlib.pyplot.plot(x, y, ‘c’, linewidth=6)
Line style:
Syntax:
matplotlib.pyplot.plot(data1, data2, linestyle = value)
Example:
matplotlib.pyplot.plot(x, y, ‘:’)
Line Style Style Name Lines
- Solid line (default) __________________
___________________
___________________
_______
-- Dashed line --------------------
: Dotted line ……………………
-. Dash-dot line -.-.-.-.-.
Change the marker type, size and
color:
To change marker type, its size and color, you can give following
additional optional arguments in plot( ) function.
marker=marker-type, markersize=value, markeredgecolor=color
Example:
import matplotlib.pyplot as pl x = [2, 8]
y = [5, 10]
pl.plot(x, y, 'b', marker='o', markersize=6, markeredgecolor='red')
pl.xlabel("Time")
pl.ylabel("Distance")
pl.show( )
marker description marker description
‘o’ circle marker ‘s’ square marker
‘x’ cross marker ‘*’ star marker
‘D’ diamond
marker
‘p’ pentagon
marker
• Timeimport matplotlib.pyplot as pl
• x=[2,6,8]
• y=[5,7,10]
• pl.plot(x,y,'ro')
• pl.xlabel(“Time")
• pl.ylabel("Distance")
• pl.show( )
import matplotlib.pyplot as pl x=[2,6,8]
y=[5,7,10]
pl.plot(x,y,'ro', linestyle='-')
pl.xlabel("Time")
pl.ylabel("Distance")
pl.show( )
import matplotlib.pyplot as plt
views=[534,258,689,401,724,689,350]
days=range(1,8)
plt.plot(days, views,
label='Youtube viewership', color='k', marker='D',
markerfacecolor='r',ls='-.',lw=3)
plt.xlabel ('Number of days')
plt.ylabel('Youtube views')
plt.legend()
plt.title("Viewer graph for youtube videos")
plt.show()
Save as pdf
import matplotlib.pyplot as mat
x=[1,2,3]
y=[5,7,4]
mat.plot(x,y,label='First')
mat.xlabel('Cost')
mat.ylabel('Speed')
mat.title('Analysis Graph')
mat.legend()
mat.savefig("d:/acet.pdf",format="pdf")
mat.show()
Plotting two lines
import matplotlib.pyplot as mat
x1=[1,2,3]
y1=[5,7,4]
x2=[1,2,3]
y2=[5,14,12]
mat.plot(x1,y1,label='First',color='cyan')
mat.plot(x2,y2,label='Second',color='g')
mat.xlabel('Cost')
mat.ylabel('Speed')
mat.title('Analysis Graph')
mat.legend()
mat.show()
Line style and width
import matplotlib.pyplot as mat
x1=[1,2,3]
y1=[5,7,4]
x2=[1,2,3]
y2=[5,14,12]
mat.plot(x1,y1,label='First',color='cyan',ls='-.',linewidth=10)
mat.plot(x2,y2,label='Second',color='g')
mat.xlabel('Cost')
mat.ylabel('Speed')
mat.title('Analysis Graph')
mat.legend()
mat.show()
Pie Chart
import matplotlib.pyplot as mat
x=[11,33,44,12,99]
y=['java','c','python','php','dotnet']
mat.pie(x,labels=y)
mat.show()
import matplotlib.pyplot as mat
x=[11,33,44,12,99]
y=['java','c','python','php','dotnet']
color=['red','green','y','k','b']
mat.pie(x,labels=y,colors=color)
mat.show()
import matplotlib.pyplot as mat
x=[11,33,44,12,99]
y=['java','c','python','php','dotnet']
color=['red','green','y','k','b']
ex=[0,0,0.2,0,0.5]
mat.pie(x,labels=y,colors=color,explode=ex)
mat.show()
import matplotlib.pyplot as mat
x=[11,33,44,12,99]
y=['java','c','python','php','dotnet']
color=['red','green','y','k','b']
ex=[0,0,0.2,0,0.5]
mat.pie(x,labels=y,colors=color,explode=ex,
shadow=True)
mat.show()
import matplotlib.pyplot as mat
x1=[1,2,3,4,5]
x2=[11,12,13,14,15]
y=[5,2,1,3,6]
mat.scatter(x1,y,label=“cost p",color='c')
mat.scatter(x2,y,label=“selling p",color='magenta')
mat.xlabel("x")
mat.ylabel("y")
mat.title("scatter")
mat.legend()
mat.show()
Histogram
import matplotlib.pyplot as mat
viewer=[24,22,33,85,41,82,55,88,1,4,99,81,38]
age=[0,10,20,30,40,50,60,70,80,90,100]
mat.hist(viewer,age,color='g',rwidth=0.5)
mat.title("histogram")
mat.show()
import matplotlib.pyplot as plt
import numpy as np
label = ['Anil', 'Vikas', 'Dharma','Mahen', 'Manish', 'Rajesh']
per = [94,85,45,25,50,54]
index = np.arange(len(label))
plt.bar(index, per)
plt.xlabel('Student Name', fontsize=5)
plt.ylabel('Percentage', fontsize=5)
plt.xticks(index, label, fontsize=5,
rotation=30)
plt.title('Percentage of Marks achieve student in ECE')
plt.show()
import matplotlib.pyplot as pl
year=['2015','2016','2017','2018']
p=[98.50,70.25,55.20,90.5]
c=['b','g','r','m']
pl.barh(year, p, color = c)
pl.xlabel("pass%")
pl.ylabel("year")
pl.show( )
import matplotlib.pyplot as pl
import numpy as np
# importing numeric python for arange( )
boy=[28,45,10,30]
girl=[14,20,36,50]
X=np.arange(4) # creates a list of 4 values [0,1,2,3]
pl.bar(X, boy, width=0.2, color='r', label="boys")
pl.bar(X+0.2, girl, width=0.2,color='b',label="girls")
pl.legend(loc="upper left") # color or mark linked to
specific data range plotted at location
pl.title("Admissions per week") # title of the chart
pl.xlabel("week")
pl.ylabel("admissions")
pl.show( )
•
Location for legend
• matplotlib.pyplot.legend(loc= ‘upper left’)
• OR
• matplotlib.pyplot.legend(loc= 2)
location string location code
upper right 1
upper left 2
lower left 3
lower right 4
center 10
•Thank You

More Related Content

Similar to UNit-III. part 2.pdf

Introduction to Pylab and Matploitlib.
Introduction to Pylab and Matploitlib. Introduction to Pylab and Matploitlib.
Introduction to Pylab and Matploitlib. yazad dumasia
 
16. Data VIsualization using PyPlot.pdf
16. Data VIsualization using PyPlot.pdf16. Data VIsualization using PyPlot.pdf
16. Data VIsualization using PyPlot.pdfRrCreations5
 
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
 
Python Pyplot Class XII
Python Pyplot Class XIIPython Pyplot Class XII
Python Pyplot Class XIIajay_opjs
 
matplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guidematplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guideArulalan T
 
A Map of the PyData Stack
A Map of the PyData StackA Map of the PyData Stack
A Map of the PyData StackPeadar Coyle
 
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
 
PPT on Data Science Using Python
PPT on Data Science Using PythonPPT on Data Science Using Python
PPT on Data Science Using PythonNishantKumar1179
 
Matplotlib 簡介與使用
Matplotlib 簡介與使用Matplotlib 簡介與使用
Matplotlib 簡介與使用Vic Yang
 
Matplotlib Review 2021
Matplotlib Review 2021Matplotlib Review 2021
Matplotlib Review 2021Bhaskar J.Roy
 
Matplotlib_Complete review_2021_abridged_version
Matplotlib_Complete review_2021_abridged_versionMatplotlib_Complete review_2021_abridged_version
Matplotlib_Complete review_2021_abridged_versionBhaskar J.Roy
 
Python for Machine Learning(MatPlotLib).pptx
Python for Machine Learning(MatPlotLib).pptxPython for Machine Learning(MatPlotLib).pptx
Python for Machine Learning(MatPlotLib).pptxDr. Amanpreet Kaur
 
Graphs made easy with SAS ODS Graphics Designer (PAPER)
Graphs made easy with SAS ODS Graphics Designer (PAPER)Graphs made easy with SAS ODS Graphics Designer (PAPER)
Graphs made easy with SAS ODS Graphics Designer (PAPER)Kevin Lee
 
Use the Matplotlib, Luke @ PyCon Taiwan 2012
Use the Matplotlib, Luke @ PyCon Taiwan 2012Use the Matplotlib, Luke @ PyCon Taiwan 2012
Use the Matplotlib, Luke @ PyCon Taiwan 2012Wen-Wei Liao
 

Similar to UNit-III. part 2.pdf (20)

Introduction to Pylab and Matploitlib.
Introduction to Pylab and Matploitlib. Introduction to Pylab and Matploitlib.
Introduction to Pylab and Matploitlib.
 
Py lecture5 python plots
Py lecture5 python plotsPy lecture5 python plots
Py lecture5 python plots
 
16. Data VIsualization using PyPlot.pdf
16. Data VIsualization using PyPlot.pdf16. Data VIsualization using PyPlot.pdf
16. Data VIsualization using PyPlot.pdf
 
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
 
Python Pyplot Class XII
Python Pyplot Class XIIPython Pyplot Class XII
Python Pyplot Class XII
 
matplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guidematplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guide
 
A Map of the PyData Stack
A Map of the PyData StackA Map of the PyData Stack
A Map of the PyData Stack
 
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
 
PPT on Data Science Using Python
PPT on Data Science Using PythonPPT on Data Science Using Python
PPT on Data Science Using Python
 
Python for Data Science
Python for Data SciencePython for Data Science
Python for Data Science
 
Seeing Like Software
Seeing Like SoftwareSeeing Like Software
Seeing Like Software
 
Matplotlib 簡介與使用
Matplotlib 簡介與使用Matplotlib 簡介與使用
Matplotlib 簡介與使用
 
Basic Analysis using Python
Basic Analysis using PythonBasic Analysis using Python
Basic Analysis using Python
 
Matplotlib Review 2021
Matplotlib Review 2021Matplotlib Review 2021
Matplotlib Review 2021
 
Matplotlib_Complete review_2021_abridged_version
Matplotlib_Complete review_2021_abridged_versionMatplotlib_Complete review_2021_abridged_version
Matplotlib_Complete review_2021_abridged_version
 
Foliumcheatsheet
FoliumcheatsheetFoliumcheatsheet
Foliumcheatsheet
 
Python Manuel-R2021.pdf
Python Manuel-R2021.pdfPython Manuel-R2021.pdf
Python Manuel-R2021.pdf
 
Python for Machine Learning(MatPlotLib).pptx
Python for Machine Learning(MatPlotLib).pptxPython for Machine Learning(MatPlotLib).pptx
Python for Machine Learning(MatPlotLib).pptx
 
Graphs made easy with SAS ODS Graphics Designer (PAPER)
Graphs made easy with SAS ODS Graphics Designer (PAPER)Graphs made easy with SAS ODS Graphics Designer (PAPER)
Graphs made easy with SAS ODS Graphics Designer (PAPER)
 
Use the Matplotlib, Luke @ PyCon Taiwan 2012
Use the Matplotlib, Luke @ PyCon Taiwan 2012Use the Matplotlib, Luke @ PyCon Taiwan 2012
Use the Matplotlib, Luke @ PyCon Taiwan 2012
 

Recently uploaded

Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 

Recently uploaded (20)

Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 

UNit-III. part 2.pdf

  • 1. Plotting using Matplot Lib Data visualization basically refers to the graphical or visual representation of information and data using charts, graphs, maps etc. pyplot is an interface, which exists in matplotlib library. To draw the lines, charts etc. first of all we have to install matplotlib library in our computer and import it in the python program. matplotlib is a package which is used to draw 2-D graphics. Installing the matplotlib : Step-1: Download the wheel package of matplotlib. To download go to the following url: https://pypi.org/project/matplotlib/#files Step-2: Now install it using following commands on command prompt: python –m pip install –U pip python –m pip install –U matplotlib
  • 2. COMMONLY USED CHART TYPES: • Line Chart • Bar Chart • Pie Chart
  • 3. Line Chart – A line chart displays information as a series of data points called “markers”. – import the matplotlib library and pyplot interface. – pyplot interface has plot( ) function to draw a line. – To set the lables for x-axis and y-axis, xlabel( ) and ylabel( ) functions are used. – Use show( ) function to display the line.
  • 4. Line Graph import matplotlib.pyplot as mat x=[1,2,3] y=[5,7,4] mat.plot(x,y,label='First') mat.xlabel('Cost') mat.ylabel('Speed') mat.title('Analysis Graph') mat.legend() mat.show()
  • 5.
  • 6. Formatting the line chart: Line : Change the line color, width and style Marker : Change the marker Type, size and color Change the line color, width and style: Line color: Syntax: matplotlib.pyplot.plot(data1, data2, color-code) Example: matplotlib.pyplot.plot(x, y, ‘r’) #’r’ is color code for red colour
  • 7. color Code Red ‘r’ Green ‘g’ Blue ‘b’ Yellow ‘y’ Magenta ‘m’ Black ‘k’ Cyan ‘c’ White ‘w’
  • 8. Line width: Syntax: matplotlib.pyplot.plot(data1, data2, linewidth=value) Example: matplotlib.pyplot.plot(x, y, ‘c’, linewidth=6) Line style: Syntax: matplotlib.pyplot.plot(data1, data2, linestyle = value) Example: matplotlib.pyplot.plot(x, y, ‘:’)
  • 9. Line Style Style Name Lines - Solid line (default) __________________ ___________________ ___________________ _______ -- Dashed line -------------------- : Dotted line …………………… -. Dash-dot line -.-.-.-.-.
  • 10. Change the marker type, size and color: To change marker type, its size and color, you can give following additional optional arguments in plot( ) function. marker=marker-type, markersize=value, markeredgecolor=color Example: import matplotlib.pyplot as pl x = [2, 8] y = [5, 10] pl.plot(x, y, 'b', marker='o', markersize=6, markeredgecolor='red') pl.xlabel("Time") pl.ylabel("Distance") pl.show( )
  • 11.
  • 12. marker description marker description ‘o’ circle marker ‘s’ square marker ‘x’ cross marker ‘*’ star marker ‘D’ diamond marker ‘p’ pentagon marker
  • 13. • Timeimport matplotlib.pyplot as pl • x=[2,6,8] • y=[5,7,10] • pl.plot(x,y,'ro') • pl.xlabel(“Time") • pl.ylabel("Distance") • pl.show( )
  • 14.
  • 15. import matplotlib.pyplot as pl x=[2,6,8] y=[5,7,10] pl.plot(x,y,'ro', linestyle='-') pl.xlabel("Time") pl.ylabel("Distance") pl.show( )
  • 16.
  • 17. import matplotlib.pyplot as plt views=[534,258,689,401,724,689,350] days=range(1,8) plt.plot(days, views, label='Youtube viewership', color='k', marker='D', markerfacecolor='r',ls='-.',lw=3) plt.xlabel ('Number of days') plt.ylabel('Youtube views') plt.legend() plt.title("Viewer graph for youtube videos") plt.show()
  • 18.
  • 19. Save as pdf import matplotlib.pyplot as mat x=[1,2,3] y=[5,7,4] mat.plot(x,y,label='First') mat.xlabel('Cost') mat.ylabel('Speed') mat.title('Analysis Graph') mat.legend() mat.savefig("d:/acet.pdf",format="pdf") mat.show()
  • 20.
  • 21. Plotting two lines import matplotlib.pyplot as mat x1=[1,2,3] y1=[5,7,4] x2=[1,2,3] y2=[5,14,12] mat.plot(x1,y1,label='First',color='cyan') mat.plot(x2,y2,label='Second',color='g') mat.xlabel('Cost') mat.ylabel('Speed') mat.title('Analysis Graph') mat.legend() mat.show()
  • 22.
  • 23. Line style and width import matplotlib.pyplot as mat x1=[1,2,3] y1=[5,7,4] x2=[1,2,3] y2=[5,14,12] mat.plot(x1,y1,label='First',color='cyan',ls='-.',linewidth=10) mat.plot(x2,y2,label='Second',color='g') mat.xlabel('Cost') mat.ylabel('Speed') mat.title('Analysis Graph') mat.legend() mat.show()
  • 24.
  • 25. Pie Chart import matplotlib.pyplot as mat x=[11,33,44,12,99] y=['java','c','python','php','dotnet'] mat.pie(x,labels=y) mat.show()
  • 26.
  • 27. import matplotlib.pyplot as mat x=[11,33,44,12,99] y=['java','c','python','php','dotnet'] color=['red','green','y','k','b'] mat.pie(x,labels=y,colors=color) mat.show()
  • 28.
  • 29. import matplotlib.pyplot as mat x=[11,33,44,12,99] y=['java','c','python','php','dotnet'] color=['red','green','y','k','b'] ex=[0,0,0.2,0,0.5] mat.pie(x,labels=y,colors=color,explode=ex) mat.show()
  • 30.
  • 31. import matplotlib.pyplot as mat x=[11,33,44,12,99] y=['java','c','python','php','dotnet'] color=['red','green','y','k','b'] ex=[0,0,0.2,0,0.5] mat.pie(x,labels=y,colors=color,explode=ex, shadow=True) mat.show()
  • 32.
  • 33. import matplotlib.pyplot as mat x1=[1,2,3,4,5] x2=[11,12,13,14,15] y=[5,2,1,3,6] mat.scatter(x1,y,label=“cost p",color='c') mat.scatter(x2,y,label=“selling p",color='magenta') mat.xlabel("x") mat.ylabel("y") mat.title("scatter") mat.legend() mat.show()
  • 34.
  • 35. Histogram import matplotlib.pyplot as mat viewer=[24,22,33,85,41,82,55,88,1,4,99,81,38] age=[0,10,20,30,40,50,60,70,80,90,100] mat.hist(viewer,age,color='g',rwidth=0.5) mat.title("histogram") mat.show()
  • 36.
  • 37. import matplotlib.pyplot as plt import numpy as np label = ['Anil', 'Vikas', 'Dharma','Mahen', 'Manish', 'Rajesh'] per = [94,85,45,25,50,54] index = np.arange(len(label)) plt.bar(index, per) plt.xlabel('Student Name', fontsize=5) plt.ylabel('Percentage', fontsize=5) plt.xticks(index, label, fontsize=5, rotation=30) plt.title('Percentage of Marks achieve student in ECE') plt.show()
  • 38.
  • 39. import matplotlib.pyplot as pl year=['2015','2016','2017','2018'] p=[98.50,70.25,55.20,90.5] c=['b','g','r','m'] pl.barh(year, p, color = c) pl.xlabel("pass%") pl.ylabel("year") pl.show( )
  • 40.
  • 41. import matplotlib.pyplot as pl import numpy as np # importing numeric python for arange( ) boy=[28,45,10,30] girl=[14,20,36,50] X=np.arange(4) # creates a list of 4 values [0,1,2,3] pl.bar(X, boy, width=0.2, color='r', label="boys") pl.bar(X+0.2, girl, width=0.2,color='b',label="girls") pl.legend(loc="upper left") # color or mark linked to specific data range plotted at location pl.title("Admissions per week") # title of the chart pl.xlabel("week") pl.ylabel("admissions") pl.show( )
  • 42.
  • 43. Location for legend • matplotlib.pyplot.legend(loc= ‘upper left’) • OR • matplotlib.pyplot.legend(loc= 2)
  • 44. location string location code upper right 1 upper left 2 lower left 3 lower right 4 center 10