0% found this document useful (0 votes)
7 views3 pages

Experiment 4

The document provides Python code examples for creating various types of visualizations using the Matplotlib library, including line graphs, bar graphs, histograms, and pie charts. Each section includes code for generating the respective chart along with sample data and customization options. The output for each visualization is indicated as a placeholder for the generated image.

Uploaded by

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

Experiment 4

The document provides Python code examples for creating various types of visualizations using the Matplotlib library, including line graphs, bar graphs, histograms, and pie charts. Each section includes code for generating the respective chart along with sample data and customization options. The output for each visualization is indicated as a placeholder for the generated image.

Uploaded by

baruahnilimakash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

EXPERI

MENT4:

AI
M:

Wri
tePythonpr
ogr
amst
ovi
sual
i
set
hel
i
negr
aph,
bargr
aph,
his
togr
am andpi
echar
tus
ing
matpl
otl
i
b.

1
.Li
neGr
aph

CODE:

i
mpor
tmat
plot
li
b.pypl
otaspl
t

#Dat
afort
hel
i
negr
aph

x=[
1,2,
3,4,
5]

y=[
2,3,
5,7,
11]

#Cr
eat
ethel
i
negr
aph

pl
t.
plot
(x,
y,mar
ker
='o'
,col
or='
b'
,l
ines
tyl
e='
-'
)

pl
t.
ti
tl
e('
Li
neGr
aph'
)

pl
t.
xl
abel
('
X-ax
is'
)

pl
t.
yl
abel
('
Y-ax
is'
)

pl
t.
gri
d()

pl
t.
show(
)

OUTPUT:(Pas
tet
hei
mage)

2.
BARGRAPH

i
mpor
tmat
plot
li
b.pypl
otaspl
t

#Dat
afort
hebargr
aph

cat
egor
ies=[
'
A',
'B'
,'
C'
,'
D']

val
ues=[
3,7,
5,1
0]
#Cr
eat
ethebargr
aph

pl
t.
bar
(cat
egor
ies
,val
ues
,col
or='
orange'
)

pl
t.
ti
tl
e('
BarGr
aph'
)

pl
t.
xl
abel
('
Cat
egor
ies
')

pl
t.
yl
abel
('
Val
ues
')

pl
t.
show(
)

OUTPUT:(Pas
tet
hei
mage)

3.
HISTOGRAM

CODE

i
mpor
tmat
plot
li
b.pypl
otaspl
t

i
mpor
tnumpyasnp

#Dat
afort
hehi
stogr
am

dat
a=np.
random.
randn(
1000)#Gener
ate1
000r
andom number
s

#Cr
eat
ethehi
stogr
am

pl
t.
his
t(dat
a,bi
ns=30,
col
or='
pur
ple'
,al
pha=0.
7)

pl
t.
ti
tl
e('
His
togr
am'
)

pl
t.
xl
abel
('
Val
ue'
)

pl
t.
yl
abel
('
Frequency'
)

pl
t.
show(
)

OUTPUT:(Pas
tet
hei
mage)

4.
PIECHART

CODE:

i
mpor
tmat
plot
li
b.pypl
otaspl
t

#Dat
afort
hepi
echar
t
s
izes=[
15,
30,
45,
10]

l
abel
s=[
'
A',
'B'
,'
C'
,'
D']

col
ors=[
'
gol
d'
,'
li
ght
cor
al'
,'
li
ght
skybl
ue'
,'
li
ght
green'
]

#Cr
eat
ethepi
echar
t

pl
t.
pie(
si
zes
,label
s=l
abel
s,col
ors
=col
ors
,aut
opct
='%1
.1
f%%'
,st
art
angl
e=1
40)

pl
t.
axi
s(
'equal
'
)#Equal
aspectr
ati
oens
urest
hatpi
eisdr
awnasaci
rcl
e.

pl
t.
ti
tl
e('
Pi
eChar
t'
)

pl
t.
show(
)

OUTPUT:(Pas
tet
hei
mage)

You might also like