0% found this document useful (0 votes)
8 views14 pages

Python Practical 2

The document discusses creating bar graphs and histograms using Python's matplotlib library. It includes code samples for drawing bar graphs with different labels, colors and styles. It also contains examples of histogram plots with varying data sets and number of bins.

Uploaded by

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

Python Practical 2

The document discusses creating bar graphs and histograms using Python's matplotlib library. It includes code samples for drawing bar graphs with different labels, colors and styles. It also contains examples of histogram plots with varying data sets and number of bins.

Uploaded by

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

Q1.

Bar graph

from matplotlib.pyplot import*


from numpy import*

x=["M1","M2","E1","E2"]
y=[25,30,14,20]

xlabel("Subject",c='r',fontsize=10)
ylabel("Marks",c='g',fontsize=10)
title("Result")
bar(x,y,color=['r','g','cyan','m'])
show()

Output:
Q

from matplotlib.pyplot import*


from numpy import*

x=["M1","M2","E1","E2"]
y=[25,30,14,20]
tick_label=['M1','M2','E1','E2']

xlabel("Subject",c='r',fontsize=10)
ylabel("Marks",c='g',fontsize=10)
title("Result")
bar(x,y,tick_label=tick_label,color=['r','g','cyan','m'],edgecolor='k',width=0.5,ls='dotted')
show()

Exercise:

Que 1. Draw bar graph


from matplotlib.pyplot import*
from numpy import*

x=['Physics','Chemistry','Maths','Bio']
y=[48,53,51,64]

xlabel("Subject",c='r',fontsize=10)
ylabel("Marks",c='g',fontsize=10)
title("Result")
bar(x,y,color=['r','g','cyan','m'],edgecolor='k',width=0.5,ls='--')
show()

Output:
Que 2

from matplotlib.pyplot import*


from numpy import*

x=[15,25,35,45]
y=[20,45,25,10]
tick_label=['15','25','35','45']
xlabel("Savings",c='r',fontsize=10)
ylabel("No of employees",c='g',fontsize=10)
title("Result")
bar(x,y,tick_label=tick_label,color=['r','g','cyan','m'],edgecolor='k',width=5,ls='--')
show()

Output:
Que 3

from matplotlib.pyplot import*


from numpy import*

x=['Cricket','Football','Badminton','Hockey','Other']
y=[34,50,24,10,82]
tick_label=['Cricket','Football','Badminton','Hockey','Other']

xlabel("Sports",c='r',fontsize=10)
ylabel("No of students",c='g',fontsize=10)
title("Result")
bar(x,y,tick_label=tick_label,color=['r','g','cyan','m','k'],edgecolor='k',width=0.9,ls='--')
show()

Output:
Que 4

from matplotlib.pyplot import*


from numpy import*

x=['Singing','Reading Books','Dancing','Painting','Others']
y=[34,50,24,10,82]
tick_label=['Singing','Reading Books','Dancing','Painting','Other']
xlabel("Hobbies",c='r',fontsize=10)
ylabel("No of students",c='g',fontsize=10)
title("Result")
bar(x,y,tick_label=tick_label,color=['r','g','cyan','m','k'],edgecolor='k',width=0.9,ls='--')
show()

Output:

Histogram:
Q1

from matplotlib.pyplot import*


from numpy import*

x=[5,23,15,46,73,89,45,78,36,92,88,84,96,76,11,65,49]
bins=5

xlabel("Age group",c='r',fontsize=10)
ylabel("No of peoples",c='g',fontsize=10)
title("Age group histogram")
hist(x,bins,histtype='bar',edgecolor='k')
show()

Output:
Q2

from matplotlib.pyplot import*


from numpy import*

x=[134,152,136,142,148,150,154]
bins=4
xlabel("Height(in cm)",c='r',fontsize=10)
ylabel("No of students",c='g',fontsize=10)
title("Age group histogram")
hist(x,bins,histtype='bar',color='cyan',edgecolor='k')
show()

Output:

Q3
from matplotlib.pyplot import*
from numpy import*

x=[11,12,13,14,27,48,51,56,49,20,22,29,30,36,37]
bins=5

xlabel("Age group",c='r',fontsize=10)
ylabel("No of illiterates",c='g',fontsize=10)
title("Illeterate persons")
hist(x,bins,histtype='bar',color='cyan',edgecolor='k')
show()

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy