0% found this document useful (0 votes)
10 views31 pages

Graph Types in Matplotlib Explained

The document provides instructions and examples for creating various types of plots using the Matplotlib library in Python, including line charts, bar charts, and histograms. It covers how to define axes, add titles and labels, customize bar properties, and plot multiple datasets. Additionally, it includes exercises for practicing these plotting techniques.

Uploaded by

bholdi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views31 pages

Graph Types in Matplotlib Explained

The document provides instructions and examples for creating various types of plots using the Matplotlib library in Python, including line charts, bar charts, and histograms. It covers how to define axes, add titles and labels, customize bar properties, and plot multiple datasets. Additionally, it includes exercises for practicing these plotting techniques.

Uploaded by

bholdi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

LINE CHART

[Link]()
• Define the x-axis and y-axis values as lists.
• Plot them on canvas using .plot() function
• Give a name to x-axis and y-axis
using .xlabel() and .ylabel() functions.
• Give a title to your plot using .title() function.
• If more than two graphs plotted then display legend
using .legend() function
• Finally, to view your plot, we use .show() function.
Python Code Graph
import [Link] as plt
x=["Mon","Tue","Wed","Thu","Fri","S
at","Sun"]
y=[2000,2800,3000,2500,2300,2500,
1000]
Python Code Graph
import [Link] as plt
x=["Mon","Tue","Wed","Thu","Fri","S
at","Sun"]
y=[2000,2800,3000,2500,2300,2500,
1000]
[Link](x,y)
[Link]()
Python Code Graph
import [Link] as plt
x=["Mon","Tue","Wed","Thu","Fri","S
at","Sun"]
y=[2000,2800,3000,2500,2300,2500,
1000]
[Link]("Day wise Tickets sold ")
[Link]()
Python Code Graph
import [Link] as plt
x=["Mon","Tue","Wed","Thu","Fri","S
at","Sun"]
y=[2000,2800,3000,2500,2300,2500,
1000]
[Link]("Day wise Tickets sold ")
[Link]("Days")
[Link]()
Python Code Graph
import [Link] as plt
x=["Mon","Tue","Wed","Thu","Fri","S
at","Sun"]
y=[2000,2800,3000,2500,2300,2500,
1000]
[Link]("Day wise Tickets sold ")
[Link]("Days")
[Link]("No of tickets sold")
[Link]()
Python Code Graph
import [Link] as plt
x=["Mon","Tue","Wed","Thu","Fri","Sa
t","Sun"]
y=[2000,2800,3000,2500,2300,2500,1
000]
[Link]("Day wise Tickets sold ")
[Link]("Days")
[Link]("No of tickets sold")
[Link]()
[Link]()
Python Code Graph
import [Link] as plt
x=["Mon","Tue","Wed","Thu","Fri","Sa
t","Sun"]
y=[2000,2800,3000,2500,2300,2500,1
000]
[Link]("Day wise Tickets sold ")
[Link]("Days")
[Link]("No of tickets sold")
[Link]([“SINGLE”])
[Link]()
[Link](Xvalue,Yvalue)
BAR CHART
[Link](Xvalue , Yvalue)
import [Link] as plt
langs = ['C', 'C++', 'Java', 'Python', 'PHP']
students = [23,17,35,29,12]
[Link](langs,students)
[Link]()
Bar customization

color Change the bar color


width Width of bar. Should be between 0 and 1
bottom Value from y-axis starts. Default is 0
align Position of x-label. Value can be ‘edge’ or ’center’
edgecolor Color of border line of bar
linewidth Width of the border line of bar
tick_label List of new labels for x axis
label Labels for legends
import [Link] as plt
langs = ['C', 'C++', 'Java', 'Python', 'PHP']
students = [23,17,35,29,12]
[Link](langs,students,width=0.25,edgecolor='r',\
linewidth=5,tick_label=['A','B','C','D','E'])
[Link]()
Plotting Multiple Bars
import numpy as np
import [Link] as plt
sub=['IP','ECO','ACC']
stud1=[10,15,30]
stud2=[20,16,18]
stud3=[19,13,20]
[Link](sub,stud1,color='b')
[Link](sub,stud2,color='g')
[Link](sub,stud3,color='r')
[Link]()
import numpy as np
import [Link] as plt
sub=['IP','ECO','ACC']
stud1=[10,15,30]
stud2=[20,16,18]
stud3=[19,13,20]
x=[Link]([0,1,2])

[Link](x,stud1,color='b',width=0.25)
[Link](x+0.25,stud2,color='g',width=0.25)
[Link](x+0.50,stud3,color='r',width=0.25)
[Link](x,sub)
[Link]()
import numpy as np
import [Link] as plt
sub=['IP','ECO','ACC']
stud1=[10,15,30]
stud2=[20,16,18]
stud3=[19,13,20]
x=[Link]([0,1,2]) #x=[Link](len(sub))

[Link](x,stud1,color='b',width=0.25,label="ramesh")
[Link](x+0.25,stud2,color='g',width=0.25,label="latha")
[Link](x+0.50,stud3,color='r',width=0.25,label="seema")
[Link](x+.25,sub)
[Link]()
[Link]()
HISTOGRAM
import [Link] as plt
import numpy as np
marks=[10,8,23,34,20,12,42,3,5,2,9,24]
[Link](marks)
[Link]()
import [Link] as plt
import numpy as np
marks=[10,8,23,34,20,12,42,3,5,2,9,24]
[Link](marks,edgecolor='r')
[Link]()
import [Link] as plt
import numpy as np
marks=[10,8,23,34,20,12,42,3,5,2,9,24]
[Link](marks,bins=2,edgecolor='r')
[Link]()
import [Link] as plt
import numpy as np
marks=[10,8,23,34,20,12,42,3,5,2,9,24]
[Link](marks,bins=4,ec='y')
[Link]("Marks")
[Link]("Count")
[Link]("Marks histogram")
[Link]()
import [Link] as plt
import numpy as np
marks=[10,8,23,34,20,12,42,3,5,2,9,24]
[Link](marks,bins=[2,6,8,12,24],ec='y',
cumulative=False)
[Link]("Marks")
[Link]("Count")
[Link]("Marks histogram")
[Link]()
EXERCISE
Write Python code for
import [Link] as plt #Statement 1
apps=["Arogya Setu","WPS Office","Cam
Scanner","WhatsApp","Telegram"]
ps_rating=[3.9,4.5,4.6,4.2,4.3]
[Link](apps,ps_rating,color='m',label=“App Rating”)
[Link]("Apps")
plt. ylabel ("Rating")
plt. legend()
plt. show()
Write the python code for plotting graph
Code
import [Link] as plt
overs=['1-10','11-20','21-30','31-40','41-50']
runs=[65,55,70,60,90]
[Link]('Over Range')
[Link]('Runs Scored')
[Link]('India Scoring Rate')
[Link](overs,runs)
[Link]( )

You might also like