0% found this document useful (0 votes)
6 views5 pages

Practice Questions

The document contains programming exercises that involve creating various types of charts using Matplotlib in Python. It includes solutions for plotting bar charts, pie charts, and line charts based on different datasets such as student heights, charity collections, unit test marks, and college admissions. Each solution is accompanied by the necessary code and a brief description of the task.

Uploaded by

poojasaini989700
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)
6 views5 pages

Practice Questions

The document contains programming exercises that involve creating various types of charts using Matplotlib in Python. It includes solutions for plotting bar charts, pie charts, and line charts based on different datasets such as student heights, charity collections, unit test marks, and college admissions. Each solution is accompanied by the necessary code and a brief description of the task.

Uploaded by

poojasaini989700
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/ 5

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:

import matplotlib.pyplot as plt

sections=['A','B','C','D','E','F']

collection=[5200, 2000, 3800, 4200, 5500,7300]

plt.pie(collection, labels=sections, autopct='%1.1f%%')

plt.title("chart showing collection amount section wise")

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

import matplotlib.pyplot as plt

Data=[[5,20,32],[25,10,17],[15,35,20]]

X=np.arange(3)

plt.plot(X, Data[0], color='b', label='range1')

plt.plot(X, Data[1], color='g', label='range2')

plt.plot(X, Data[2], color='r', label='range3')

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:

import matplotlib.pyplot as plt

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:

import matplotlib.pyplot as plt

stream=['BCA','BBA','MCA','MBA','BLIB']

admisn=[20, 40, 35, 25, 10]

plt.pie(admisn, labels=stream, autopct='%1.1f%%')

plt.title("chart showing admissions stream wise")

plt.show()

output:

You might also like