Practice Questions
Practice Questions
Q1: Write a program to plot a bar chart from the height of some students in your class.
names=[‘Anu’, ’Dev’, ’Raj’, ’Sam’, ‘John’]
height=[6.0, 5.5, 5.9, 5.0, 5.2]
Soln:
import matplotlib.pyplot as plt
height=[6.0, 5.5, 5.9, 5.0, 5.2]
names=['Anu','Dev','Raj','Sam','john']
plt.bar(names,height)
plt.xlabel('names')
plt.ylabel('height')
plt.show()
output:
Q2. Birla school celebrated volunteering week where each section of class XI dedicated a
day for collecting amount for charity being supported by the school. Section A volunteered
on Monday, B on Tuesday, C on Wednesday and so on. There are six section in class XI.
Amount collected by sections A to F are 5200, 2000, 3800, 4200, 5500,7300. Write a
program to create a pie chart showing collection amount section wise.
Soln:
sections=['A','B','C','D','E','F']
plt.show()
output:
Q3: Create multiple line charts on common plot with title and legend.
Data = [ 5 , 20 , 32 ] , [ 25 , 10 , 17 ] , [ 15 , 35 , 20]
Soln:
import numpy as np
Data=[[5,20,32],[25,10,17],[15,35,20]]
X=np.arange(3)
plt.legend(loc='upper left')
plt.title('multiline chart')
plt.show()
output:
Q4: Marks is a list that stores marks of a student in 10 unit tests. |Write a program to plot
the student's performance in these 10 unit tests.
marks=[12,10,10,15,17,25,12,22,35,40]
Soln:
ut=[1,2,3,4,5,6,7,8,9,10]
marks=[12,10,10,15,17,25,12,22,35,40]
plt.plot(ut, marks)
plt.xlabel('unit tests')
plt.ylabel('marks')
plt.show()
output:
Q5: In an engineering college number of admission stream wise in the current year are
BCA=20, BBA=40, MCA=35, MBA=25, BLIB=10. write a program to create pie chart to
creating a wedge stream.
Ans:
stream=['BCA','BBA','MCA','MBA','BLIB']
plt.show()
output: