Python :
Decision Making and Loop
Punit A. Lathiya
Assistant Professor
EC Department
GEC Rajkot
Syllabus : 3151108
Syllabus : 3151108
Teaching and Examination Scheme
Books
Online Courses
• [Link]
• [Link]
• [Link]
Index
• Modules to import
• Types of Plots
• Multiple Plots
• Labeling
Introduction
• matplotlib stands for mathematical plotting library.
• Author : John D. Hunter
• Open Source
• It supports both interactive and non-interactive modes
of plotting and can save images in a variety of formats
like (JPEG, PS, PDF, PNG etc).
• Two package within matplotlib exists.,
▫ [Link] and
▫ [Link]
Introduction
• To install matplotlib:
▫ open command prompt:
pip install matplotlib
• Importing matplotlib:
▫ import matplotlib
▫ import [Link] as plt
Plot Types Plot Styling Plot Labels
• Line plot • Line plot • Xlabel
• Scatter plot ▫ Line width • Ylabel
• Bar chart ▫ Line Marker • Title
• Pie chart
▫ Line Color • Grid
• Histogram
• Multiple plot in one
• Multiple plot in subplot
Features of Plot
• Figure
• Axes
• Xlabel
• Ylabel
• Title
• Grid
• Legend
• Linestyle, Linecolor, Markers
Line Plot
Multiple Plots – within same plot
Marker Type
Multiple Plots – Separate plots
Figure-1
Figure-2
Multiple Plots – Using Subplot
Syntax : [Link](row, col, fig_num)
Figure-1
Sine Cosine
Subplot(2,2,1) Subplot(2,2,2)
Tan Power
Subplot(2,2,3) Subplot(2,2,4)
Multiple Plots – Using Subplot
[Link](x,y,'-x',linewidth=2,color='red')
[Link](["square","cube",], loc = "upper right" )
Method for applying Line Colors
b: blue
r: red
g: green
c: cyan
m: magenta
y: yellow
k: black
w: white
Method for applying Line style
• Using Linestyle Command:
▫ Solid
▫ Dashed
▫ Dotted
▫ DashDot
Method for applying Line style
• Using ls command:
▫ ‘-’ : Solid
▫ ‘--’ : Dashed
▫ ‘:’ : Dotted
▫ ‘-.’ : Dashdot
Various plot Types
• import [Link] as plt
• x = [1,2,3,4,5,6,7,8,9,10]
• y = [2.4,5.9,8,9.5,7,5.6,8.2,4.5,2,5]
• # Line Plot
• [Link](x,y)
• [Link]('Line Graph')
• [Link]()
Various plot Types
• import [Link] as plt
• x = [1,2,3,4,5,6,7,8,9,10]
• y = [2.4,5.9,8,9.5,7,5.6,8.2,4.5,2,5]
• # Bar Plot
• [Link](x,y)
• [Link]('Bar Graph')
• [Link]()
Various plot Types
• import [Link] as plt
• # Pie Plot
• fruit = 'APPLE', 'BANANA',
'MANGO', 'KIVI'
• num = [15, 30, 45, 10]
• [Link](num,labels=fruit)
• [Link]('Pie Graph')
• [Link]()
Various plot Types
• import [Link] as plt
• x = [1,2,3,4,5,6,7,8,9,10]
• y = [2.4,5.9,8,9.5,7,5.6,8.2,4.5,2,5]
• #Scatter Plot
• [Link](x,y)
• [Link]('Scatter Graph')
• [Link]()
Various plot Types
• import [Link] as plt
• x = [1,2,3,4,5,6,7,8,9,10]
• y = [2.4,5.9,8,9.5,7,5.6,8.2,4.5,2,5]
• #Histogram Plot
• [Link](y)
• [Link]('Histogram Plot')
• [Link]()
Thank You