0% found this document useful (0 votes)
79 views

Term 2 - Record Book Programs

Uploaded by

bishan.c.2006
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Term 2 - Record Book Programs

Uploaded by

bishan.c.2006
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Write a Python program to display a BAR CHART of the number of students in a

school.
(i) Use different colors for each bar.
(ii) Title for x axis should be „Groups‟ and title for y axis should be „Number of
Students
(iii) Ensure the title of chart is “Group wise Students” and grid line must be shown.
Sample data: Group: I, II, III, IV and Strength: 38, 30, 45, 49

import matplotlib.pyplot as plt

Group=['I','II','III','IV']

Strength=[38,30,45,49]

plt.bar(Group, Strength, color=['red','green','blue','black'])

plt.xlabel('Group')

plt.ylabel('Number of students')

plt.title('Group wise students')

plt.grid(True)

plt.show()
Write a Python program to display the given Result using a BAR CHART
Maths Science SST
Amit 100 100.0 60.0
Mohan 95 100.0 57.48
Sudha 85 100.0 53.58
(i) Set the title of graph is “Result Analysis”
(ii) Display the legends.
(iii) Display the label of x axis to “Name” and y axis to “Score”

import matplotlib.pyplot as plt

import numpy as np

Subject=['Maths','Science','SST']

Amit=[100,100.0,60.0]

Mohan=[95,100.0,57.48]

Sudha=[85,100.0,53.58]

x_axis=np.arange(len(Subject))

plt.bar(x_axis-0.25, Amit, 0.25, label='Amit')

plt.bar(x_axis, Mohan, 0.25, label='Mohan')

plt.bar(x_axis+0.25, Sudha, 0.25, label='Sudha')

plt.xticks(x_axis, Subject)

plt.legend(loc=1)

plt.xlabel("Name")

plt.ylabel("Score")

plt.title("Result Analysis")

plt.show()
Write the code to draw the following line graph.

(i) Set the appropriate label to x-axis and y-axis.


(ii) Set the title of Graph “Number of Students”
(iii) Show the grid lines.
import matplotlib.pyplot as plt
Group=[1,2,3]
No_Students=[40,50,10]
plt.plot(Group,No_Students)
plt.grid(True)
plt.xlabel("Class")
plt.ylabel("Students")
plt.title("Number of Students in Class")
plt.show()
Draw the following bar graph representing the number of students in each class.

(i) Set the appropriate label to x-axis and y-axis.


(ii) Set the title of Graph “Number of Students”

import matplotlib.pyplot as plt

Group=['VII','VIII','IX','X']

No_Students=[40,45,35,45]

plt.bar(Group,No_Students)

plt.xlabel("Class")

plt.ylabel("Students")

plt.title("Number of Students in Class")

plt.show()
Write a program to plot a bar chart in python to display the result of a school for five
consecutive years.

SOURCE CODE:

import matplotlib.pyplot as pl

year=['2015','2016','2017','2018','2019'] # list of years

p=[98.50,70.25,55.20,90.5,61.50] #list of pass

j=['b','g','r','m','c'] # color code of bar charts

pl.bar(year, p, width=0.2, color=j) # bar( ) function to create the

pl.xlabel("year") # label for x-axis

pl.ylabel("Pass%") # label for y-axis

pl.show( ) # function to display bar chart


Create multiline chart on common plot where three data range plotted on same chart. The
data range(s) to be plotted are.

data=[[5,25,45,20],[8,1,29,27],[9,29,27,39]]

import numpy as np

import matplotlib.pyplot as plt

data=[[5,25,45,20],[8,1,29,27],[9,29,27,39]]

x=np.arange(4)

plt.plot(x,data[0],color='b',label='range 1')

plt.plot(x,data[1],color='g',label='range 2')

plt.plot(x,data[2],color='r',label='range 3')

plt.legend(loc='upper left')

plt.title('Multi range line chart')

plt.xlabel('X')

plt.xlabel('Y')

plt.show()
A survey gathers heights and weight of 50 participates and recorded the

participants age as

Ages=[40,56,46,58,79,70,67,46,32,91,92,93,47,95,69,69,56,50,30,9,29,29,0,31,21,14,18,1

6,18,76,68,69,78,81,71,91,71,01,69,78,77,54,59,59,41,51,48,49,76,10]

import numpy as np

import matplotlib.pyplot as plt

Ages=[40,56,46,58,79,70,67,46,32,91,92,93,47,95,69,69,56,50,30,90,29,29,\

45,31,21,14,18,16,18,76,68,69,78,81,71,91,71,30,69,78,77,\

54,59,59,41,51,48,49,76,10]

plt.hist(Ages,bins=10)

plt.title('Participates Ages Histogram')

plt.show()
Write a program that reads from a csv file (marks.csv stored in desired

location) in a data frame then add a column Total storing total marks in three subjects

and another column for storing average marks. Print the data frame after adding these

columns.

import pandas as pd

df=pd.read_csv('c:\\data\marks.csv',names=['Name','Marks1','Marks2','Marks3'])

print('DataFrame after fetching data from csv file')

print(df)

df['Total']=df['Marks1']+df['Marks2']+df['Marks3']

df['AvgMarks']=df['Total']/3

print("Dataframe after Calculation")

print(df)

You might also like