Matplotlib Bov
Matplotlib Bov
tlib
WHAT IS
MATPLOTLIB
Matplotlib is a plotting library for the Python programming language and its numerical mathematics
extension NumPy.
WHY MATPLOTLIB
Matplotlib makes easy things easy and hard things possible. Create publication quality plots. Make
interactive figures that can zoom, pan, update
Istallation&importing matplotlib
we can install
we can use it simply
matplotlib
by using a command
inside anaconda
called
"pip install
environment
matplotlib"
0
04 pie
c hart
plt. plot()
The basic syntax for creating line
plots is plt. plot(x,y), where x and y are
arrays of the same length that specify
the (x, y) pairs that form the line
we can also change the we can also change the if we want to change the
marker edge colour using marker colour using entire colour we use
mec(marker edge color) mfc(marker face colour) 'color'attribute
line style
ex:linewidth='5.6
LABLES&
TITLESlables labl
e
lables play a imp role in graph
we add l a b l e s for better understanding of
graph
TITLE
Titles
Subplot
subplot function
this t i tle func tio n ad d s t i tle to the
helps to create multiple plots as
graphs at once g rap h
graphs
With pyplot we c an use the func tion to draw
the bar graph which are used to represent 20
c ategoral variables
ex:
x=np.array(["A","B","C "])
y=np.array([6,3,9]) 1
plt.bar(x,y) 5
the output will be a bar graph
if we need a horizontal graph
ex: plt.barh(x,y) 10
observation.
x=np.array([4,8,11,9,10,6])
y= np.array([99,111,87,94,88,33])
plt.scatter(x,y) plt.show()
We can add two scatterplot functions &we can plot different colour points on graph.
The output will be a graph with two different coloured points on graph
By default the colours will be blue & orange we can also change the colour for each scatter
plt.scatter(x,y,color="red")
We can also set different colours for each dot by using an array of colors we can also set
ex: x=np.random.normal(170,10,250)
( c reating a random values)
print(x)
output: this will generate 250 values around 170 with a
standard deviation of 10
To draw the histogram for the data
ex: x=np.random.normal(170,10,250)
plt.hist(
x)
plt.show
()
output: It creates an histogram,hist function is used to
create a histogram, the array is sent inside the hist function
PI EC HAR
T Pie charts helps in easy understanding of data
plt.pie(
y=np.array([55,20,6] )
y)
plt.show C ost C ost
() 3 1
33.3% 33.3
1.This will create a pie chart the pie chart draws each piece which can be %
3.We canasalso
called add the lables
an"wedge" byh "lable"
for eac value inparameter
an array
the lable
2.By parameter
default tehe plotmust befrom
starts an array with
the "x" onemoves
axist lable "c ounter-c loc kwise"
witheach wedge
y=np.array([55,20,6] )
l=["A","B","C"]
plt.pie(y,lables=l)
plt.show()
C ost
2
33.3%
To change the start angle we use can use start angle
parameter
y=np.array([55,20,6] )
anu