SlideShare uma empresa Scribd logo
1 de 26
Baixar para ler offline
Algorithmic Efficiency
Intro, Complexity
Finding Complexities
Best, Worst & Average Cases
-> By Apni Kaksha <-
Data
Data is one of the most valuable things today.
All Big companies stores data, which helps in diagnosis, focused services
and many more.
It basically means graphical or visual representation of data & statistics using
elements like charts, graphs and maps,etc.
We can see patterns, trends, relations, etc. in the data.
Data Visualization
Library
It provides many interfaces & functionality for 2D-graphics in various forms.
Basically, it’s a high quality plotting library of python.
PyPlot is such a module in Matplotlib.
PyPlot
Matplotlib comes pre-installed with anaconda.
To run every command we need to write :
matplotlib.pyplot.<command>
Let’s better do :
import matplotlib.pyplot as pl
pl.plot(<x>,<y>)
Shorter way
Numpy
Numpy is a module of python that offers functions for fast mathematical
computation on arrays.
Arrays is a named group of homogeneous elements.
It’s very similar to lists.
All elements are of same datatype.
Functionality is different. .
Creating Array
import numpy as np
L=[1,2,3,4]
a=np.array(L) makes ‘a’ array from List ‘L’.
print( type(a) ) numpy.ndarray
print(a.shape ) (1,)
print(a.itemsize ) 4
print(a.dtype) dtype(‘int32’)
Creating Arrays
import numpy as np
a=np.arange(<start>, <stop>, <step>, <dtype>)
a=np.arange( 1,9,3,np.float32 )
a=np.linespace(<start>,<stop>,<number of values to be generated>)
will generate elements at equal intervals.
a=np.arange( 1,9,2 )
ends at 8
import numpy as np
import matplotlib.pyplot as pl
a=np.linspace(1,5,6)
b=np.log(a)
pl.plot(a,b)
pl.xlabel(‘This shows on x axis’)
pl.ylabel(‘This shows on y axis’)
pl.show( )
Plotting using numpy
ends at 5
pl.plot(a-1, b-1, 'b')
pl.plot(a, b, 'r')
pl.plot(a+1, b+1, linewidth=2, linestyle='dashed',
marker='d', markersize=4, markeredgecolor= 'red' )
pl.plot(a+2, b+2, 'bd', linestyle = 'dashdot')
Changing style
Blue & Diamond
Charts
BAR CHART PIE CHART LINE CHART
Bar Chart
import matplotlib.pyplot as pl
a=[1,2,3,4,5]
b=[1,4,9,16,25]
pl.bar(a,b)
pl.xlabel(‘N)
pl.ylabel(‘N*N’)
pl.show( )
Default width of bars : 0.8 units
Styling bars
a=[‘Grapes’, ‘Banana’, ‘Apple’, ‘Guava’]
plt.bar(a,b,width = [0.2, 0.5, 0.3, 0.8] )
plt.bar(a,b,color = [‘g’, ‘r’, ‘b’, ‘black’] )
Color & width are applied in left to right order, but the bars are plotted in
sorted order.
Styling bars
V =[[5,25,45,20], [4,23,49,17], [6,22,47,19]]
X=np.arange(4)
plt.bar(X, V[0], color=‘b’, width=0.25,label=‘a’)
plt.bar(X+0.25, V[1], color=‘g’, width=0.25,label=‘b’)
plt.bar(X+0.50, V[2], color=‘r’, width=0.25,label=‘c’)
plt.legend(loc='upper left')
Color & width are applied in left to right order, but the bars are plotted in
sorted order.
Horizontal Bar Chart
import matplotlib.pyplot as plt
a=[‘Grapes’, ‘Banana’, ‘Apple’, ‘Guava’]
x=[4,1,2,5]
plt.barh(a, x)
Pie Chart
C=[4,1,8,9]
D=[A1, B1, A2, B2]
plt.axis(‘equal’)
plt.pie(C,labels=D)
Colors may differ. For circular shape.
CLR=[‘green’, ‘blue’, ‘red’, ‘yellow’]
E=[0,0,0.1,0.15]
pl.pie(C, colors=CLR, autopct=‘%2.2f%%’, explode=E)
Styling Pie Charts
Colors may differ.
Styling Pie Chart
C=[4,1,8,9]
D=[A1, B1, A2, B2]
plt.pie(C,labels=D, autopct= ‘%1.1f%%’)
40.9%
18.2%
4.5%
36.4%
Colors may differ.
‘%[FLAG][WIDTH] . [PRECISION]type’
‘%[FLAG][WIDTH] . [PRECISION]type’
It’s a special string which defines the structure of a string.
WIDTH specifies the min. number of characters in the string.
PRECISION is the number of digits till which rounding off takes place after decimal.
type specifies the datatype. Single % specifies it’s a special string,
That’s why we use %%.
‘%3d’ - 24 = _24
‘%05i’ - 24 = 00024
‘%03d%%’ - 24 = 024%
‘%6.1f’ - 24.2 = _24.20
‘%3.3f%%’ - 24.2 = 24.200%
Customizing Chart
plt.title(‘Student’s data’)
X= [0,1,2,3]
Y= [5,25,45,20]
plt.xlim(3.5,-0.5)
plt.ylim(-50,50)
plt.title(‘Student’s data’)
plt.plot(X,Y)
Customizing Chart
plt.title(‘Student’s data’)
X= [0,1,2,3]
Y= [5,25,45,20]
plt.xticks([0,1,2,3],[‘a’, ‘b’, ‘c’, ‘d’])
plt.bar(X,Y)
plt.title(‘Student’s data’)
16. Data VIsualization using PyPlot.pdf

Mais conteúdo relacionado

Semelhante a 16. Data VIsualization using PyPlot.pdf

A Map of the PyData Stack
A Map of the PyData StackA Map of the PyData Stack
A Map of the PyData StackPeadar Coyle
 
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
 
PPT on Data Science Using Python
PPT on Data Science Using PythonPPT on Data Science Using Python
PPT on Data Science Using PythonNishantKumar1179
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfUmarMustafa13
 
Presentation: Plotting Systems in R
Presentation: Plotting Systems in RPresentation: Plotting Systems in R
Presentation: Plotting Systems in RIlya Zhbannikov
 
Introduction to Pylab and Matploitlib.
Introduction to Pylab and Matploitlib. Introduction to Pylab and Matploitlib.
Introduction to Pylab and Matploitlib. yazad dumasia
 
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...HendraPurnama31
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesAndrew Ferlitsch
 
Lecture 1 Pandas Basics.pptx machine learning
Lecture 1 Pandas Basics.pptx machine learningLecture 1 Pandas Basics.pptx machine learning
Lecture 1 Pandas Basics.pptx machine learningmy6305874
 
python-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptxpython-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptxAkashgupta517936
 
De-Cluttering-ML | TechWeekends
De-Cluttering-ML | TechWeekendsDe-Cluttering-ML | TechWeekends
De-Cluttering-ML | TechWeekendsDSCUSICT
 
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 1
Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Kyiv 2017, Day 1Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Kyiv 2017, Day 1
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 1Volodymyr Bogdanov
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxAbhishek Tirkey
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxGauravPandey43518
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..Kamarudheen KV
 

Semelhante a 16. Data VIsualization using PyPlot.pdf (20)

NUMPY
NUMPY NUMPY
NUMPY
 
A Map of the PyData Stack
A Map of the PyData StackA Map of the PyData Stack
A Map of the PyData Stack
 
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
 
Basic Analysis using Python
Basic Analysis using PythonBasic Analysis using Python
Basic Analysis using Python
 
PPT on Data Science Using Python
PPT on Data Science Using PythonPPT on Data Science Using Python
PPT on Data Science Using Python
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdf
 
Presentation: Plotting Systems in R
Presentation: Plotting Systems in RPresentation: Plotting Systems in R
Presentation: Plotting Systems in R
 
Introduction to Pylab and Matploitlib.
Introduction to Pylab and Matploitlib. Introduction to Pylab and Matploitlib.
Introduction to Pylab and Matploitlib.
 
interenship.pptx
interenship.pptxinterenship.pptx
interenship.pptx
 
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning Libraries
 
Intro matlab
Intro matlabIntro matlab
Intro matlab
 
Lecture 1 Pandas Basics.pptx machine learning
Lecture 1 Pandas Basics.pptx machine learningLecture 1 Pandas Basics.pptx machine learning
Lecture 1 Pandas Basics.pptx machine learning
 
python-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptxpython-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptx
 
De-Cluttering-ML | TechWeekends
De-Cluttering-ML | TechWeekendsDe-Cluttering-ML | TechWeekends
De-Cluttering-ML | TechWeekends
 
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 1
Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Kyiv 2017, Day 1Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Kyiv 2017, Day 1
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 1
 
Lecture 9.pptx
Lecture 9.pptxLecture 9.pptx
Lecture 9.pptx
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..
 

Último

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Último (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

16. Data VIsualization using PyPlot.pdf

  • 1. Algorithmic Efficiency Intro, Complexity Finding Complexities Best, Worst & Average Cases -> By Apni Kaksha <-
  • 2. Data Data is one of the most valuable things today. All Big companies stores data, which helps in diagnosis, focused services and many more.
  • 3. It basically means graphical or visual representation of data & statistics using elements like charts, graphs and maps,etc. We can see patterns, trends, relations, etc. in the data. Data Visualization
  • 4. Library It provides many interfaces & functionality for 2D-graphics in various forms. Basically, it’s a high quality plotting library of python. PyPlot is such a module in Matplotlib.
  • 5. PyPlot Matplotlib comes pre-installed with anaconda. To run every command we need to write : matplotlib.pyplot.<command> Let’s better do : import matplotlib.pyplot as pl pl.plot(<x>,<y>) Shorter way
  • 6. Numpy Numpy is a module of python that offers functions for fast mathematical computation on arrays. Arrays is a named group of homogeneous elements. It’s very similar to lists. All elements are of same datatype. Functionality is different. .
  • 7. Creating Array import numpy as np L=[1,2,3,4] a=np.array(L) makes ‘a’ array from List ‘L’. print( type(a) ) numpy.ndarray print(a.shape ) (1,) print(a.itemsize ) 4 print(a.dtype) dtype(‘int32’)
  • 8. Creating Arrays import numpy as np a=np.arange(<start>, <stop>, <step>, <dtype>) a=np.arange( 1,9,3,np.float32 ) a=np.linespace(<start>,<stop>,<number of values to be generated>) will generate elements at equal intervals. a=np.arange( 1,9,2 ) ends at 8
  • 9.
  • 10. import numpy as np import matplotlib.pyplot as pl a=np.linspace(1,5,6) b=np.log(a) pl.plot(a,b) pl.xlabel(‘This shows on x axis’) pl.ylabel(‘This shows on y axis’) pl.show( ) Plotting using numpy ends at 5
  • 11. pl.plot(a-1, b-1, 'b') pl.plot(a, b, 'r') pl.plot(a+1, b+1, linewidth=2, linestyle='dashed', marker='d', markersize=4, markeredgecolor= 'red' ) pl.plot(a+2, b+2, 'bd', linestyle = 'dashdot') Changing style Blue & Diamond
  • 12.
  • 13. Charts BAR CHART PIE CHART LINE CHART
  • 14. Bar Chart import matplotlib.pyplot as pl a=[1,2,3,4,5] b=[1,4,9,16,25] pl.bar(a,b) pl.xlabel(‘N) pl.ylabel(‘N*N’) pl.show( ) Default width of bars : 0.8 units
  • 15. Styling bars a=[‘Grapes’, ‘Banana’, ‘Apple’, ‘Guava’] plt.bar(a,b,width = [0.2, 0.5, 0.3, 0.8] ) plt.bar(a,b,color = [‘g’, ‘r’, ‘b’, ‘black’] ) Color & width are applied in left to right order, but the bars are plotted in sorted order.
  • 16.
  • 17. Styling bars V =[[5,25,45,20], [4,23,49,17], [6,22,47,19]] X=np.arange(4) plt.bar(X, V[0], color=‘b’, width=0.25,label=‘a’) plt.bar(X+0.25, V[1], color=‘g’, width=0.25,label=‘b’) plt.bar(X+0.50, V[2], color=‘r’, width=0.25,label=‘c’) plt.legend(loc='upper left') Color & width are applied in left to right order, but the bars are plotted in sorted order.
  • 18. Horizontal Bar Chart import matplotlib.pyplot as plt a=[‘Grapes’, ‘Banana’, ‘Apple’, ‘Guava’] x=[4,1,2,5] plt.barh(a, x)
  • 19. Pie Chart C=[4,1,8,9] D=[A1, B1, A2, B2] plt.axis(‘equal’) plt.pie(C,labels=D) Colors may differ. For circular shape.
  • 20. CLR=[‘green’, ‘blue’, ‘red’, ‘yellow’] E=[0,0,0.1,0.15] pl.pie(C, colors=CLR, autopct=‘%2.2f%%’, explode=E) Styling Pie Charts Colors may differ.
  • 21. Styling Pie Chart C=[4,1,8,9] D=[A1, B1, A2, B2] plt.pie(C,labels=D, autopct= ‘%1.1f%%’) 40.9% 18.2% 4.5% 36.4% Colors may differ. ‘%[FLAG][WIDTH] . [PRECISION]type’
  • 22. ‘%[FLAG][WIDTH] . [PRECISION]type’ It’s a special string which defines the structure of a string. WIDTH specifies the min. number of characters in the string. PRECISION is the number of digits till which rounding off takes place after decimal. type specifies the datatype. Single % specifies it’s a special string, That’s why we use %%.
  • 23. ‘%3d’ - 24 = _24 ‘%05i’ - 24 = 00024 ‘%03d%%’ - 24 = 024% ‘%6.1f’ - 24.2 = _24.20 ‘%3.3f%%’ - 24.2 = 24.200%
  • 24. Customizing Chart plt.title(‘Student’s data’) X= [0,1,2,3] Y= [5,25,45,20] plt.xlim(3.5,-0.5) plt.ylim(-50,50) plt.title(‘Student’s data’) plt.plot(X,Y)
  • 25. Customizing Chart plt.title(‘Student’s data’) X= [0,1,2,3] Y= [5,25,45,20] plt.xticks([0,1,2,3],[‘a’, ‘b’, ‘c’, ‘d’]) plt.bar(X,Y) plt.title(‘Student’s data’)