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

Practical_File4_Class_10_AI_Python_Matplotlib

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)
33 views

Practical_File4_Class_10_AI_Python_Matplotlib

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

Class 10 AI Term II Programs

Instructions:

1. Open this file in Google Colab. Link is as follows: https://colab.research.google.com/drive/1kqzYaA_k4dpSJWj5neYM4lcmoqvIkE_y?


usp=sharing

2. Add Text on the top and write your details like name, class-sec, Admn No.

3. You can modify color, style and other attributes if you want.

4. Execute all programs and take the print with output.

Link for additional reference:

https://www.w3schools.com/python/matplotlib_intro.asp

Q1-Given the school result data, analyses the performance of the students on different parameters,

e.g subject wise or class wise.

1 # import pandas and matplotlib


2 import pandas as pd
3 import matplotlib.pyplot as plt
4
5 # Simple Line Chart with setting of Label of X and Y axis,
6 # title for chart line and color of line
7 subject = ['Physic','Chemistry','Mathematics', 'Biology','Computer']
8 marks =[80,75,70,78,82]
9 # To draw line in red colour
10
11 plt.plot(subject,marks,'r',marker ='*')
12 # To Write Title of the Line Chart
13
14 plt.title('Marks Scored')
15 # To Put Label At Y Axis
16
17 plt.xlabel('SUBJECT')
18 # To Put Label At X Axis
19
20 plt.ylabel('MARKS')
21 plt.show()
22

Q-2: Write a program to plot a bar chart in python to display the result of a school for five consecutive years.

1 import matplotlib.pyplot as pl
2
3 year=['2019','2020','2021','2022','2023'] # list of years
4 p=[98.50,70.25,55.20,90.5,61.50] #list of pass percentage
5 j=['b','g','r','m','c'] # color code of bar charts
6 pl.bar(year, p, width=0.2, color=j)
7 pl.xlabel("year") # label for x-axis
8 pl.ylabel("Pass%") # label for y-axis
9 pl.title('Result Analysis of XYZ School')
10 pl.show( ) # function to display bar chart
11

Q-3: Write a program to display a line chart based on given data

1 import numpy as np
2 import matplotlib.pyplot as plt
3
4 x = np.array([80, 85, 90, 95, 100, 105, 110, 115, 120, 125])
5 y = np.array([240, 250, 260, 270, 280, 290, 300, 310, 320, 330])
6
7 plt.plot(x, y, color='red',linestyle='dashed')
8
9 plt.title("Sports Watch Data")
10 plt.xlabel("Average Pulse")
11 plt.ylabel("Calorie Burnage")
12
13 plt.show()
14

Q4- Write a program to display a scatter chart by creating random arrays for x-points, y-points, colors and sizes

1 import matplotlib.pyplot as plt


2 import numpy as np
3
4 x = np.random.randint(50, size=(100))
5 y = np.random.randint(50, size=(100))
6 colors = np.random.randint(100, size=(100))
7 sizes = 10 * np.random.randint(50, size=(100))
8
9 plt.scatter(x, y, c=colors, s=sizes, alpha=0.5, cmap='nipy_spectral')
10 #cmap is used to display system color map
11
12 plt.colorbar()
13
14 plt.show()
15

Q5- Write a program to plot a pie chart representing number of students in each house of class 10

1 import matplotlib.pyplot as plt


2 num = [112, 89, 93, 77, 80, 123]
3 houses = ['Ganga', 'Narmada', 'Sabarmati', 'Kaveri', 'Tapti', 'Mahi']
4 c = ['blue','green','cyan','orange','yellow','red']
5 e = [0,0.2,0,0,0.4,0.1]
6 plt.axis("equal") #to display the pie chart as a perfect circle
7 plt.pie(num, labels = houses, autopct = "%02.2F%%", colors = c)
8 plt.title('No of students per house \n', fontsize=20)
9 plt.legend()
10 plt.show()
11

Q6- Write a program to plot a histogram showing frequency distribution table on height of 250 people.

1 import matplotlib.pyplot as plt


2 import numpy as np
3
4 #normal()- will generate random values which will concentrate around 170
5 #with standard deviation 10.
6
7 x = np.random.normal(170, 10, 250)
8 plt.hist(x, color='red')
9 plt.title('Frequency Distribution table')
10 plt.xlabel('Height in cms')
11 plt.ylabel('No. of persons')
12 plt.show()
13

Q7- Write a program to plot a bar graph to compare AQI of different cities.

1 import matplotlib.pyplot as plt


2
3 st = ['Delhi','Jaipur', 'Ahmedabad','Cochi','Kolkata', 'Guwahati','Srinagar']
4 AQI1 = [375,240,180,120,210,90,60]
5 AQI2 = [255,190,150,100,179,95,50]
6 plt.bar(st,AQI1, label='Nov 2022')
7 plt.bar(st,AQI2, label='Sep 2022')
8 plt.xlabel('Cities')
9 plt.ylabel('Air Quality Index')
10 plt.title('AQI in Nov 2022', fontsize=26)
11 plt.legend()
12 plt.show()
13

Q8- Write a program to plot a line chart to show sales of product.

1 import matplotlib.pyplot as plt


2 x = ['Delhi', 'Mumbai', 'Chennai', 'Pune']
3 y = [350, 200, 460, 500]
4 y1 = [180, 270, 310, 700]
5 plt.xlabel('City')
6 plt.ylabel('Sales in Million')
7 plt.title('Sales Recorded in Major Cities')
8 plt.plot(x, y, label='2022') # to plot the chart
9 plt.plot(x,y1, label='2021')
10 plt.legend()
11 plt.show()
12
Q9- Write a program to show comparative analysisspeed and age of cars for 2 days

1 import matplotlib.pyplot as plt


2 import numpy as np
3
4 #day one, the age and speed of 13 cars:
5 x1 = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
6 y1 = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86])
7 plt.scatter(x1, y1,label='Day-1')
8
9 #day two, the age and speed of 15 cars:
10 x2 = np.array([2,2,8,1,15,8,12,9,7,3,11,4,7,14,12])
11 y2 = np.array([100,105,84,105,90,99,90,95,94,100,79,112,91,80,85])
12 plt.scatter(x2, y2, label='Day-2')
13 plt.title('Age vs Speed of car analysis')
14 plt.legend()
15 plt.show()
16

Q10- Write a program to display Pie chart on Favourite Activities of XYZ society residents

1 import matplotlib.pyplot as plt


2 num = [80,36,48,24,16]
3 activities = ['Walking','Swimming','Cycling','Golf','Other']
4 plt.axis("equal") #to display the pie chart as a perfect circle
5 plt.pie(num, labels = activities, autopct="%02.2F%%")
6 plt.title('Favourite Activities of XYZ Society Residents \n')
7 plt.show()

Q11- Write a program to display frequency distribution of marks of 2 classes using Line chart

1 import matplotlib.pyplot as plt


2 # Plot frequency of marks using line chart
3 marks= [97,99,65,99,77,89,77,67,67,99,68,45,55,77,45,33]
4 marks1= [98,99,65,98,77,84,76,65,67,98,65,45,55,76,33,33]
5 plt.plot(marks, 'm:', label='Class10A')
6 plt.plot(marks1, 'g--', label='Class10B')
7 plt.title('Frequency distribution')
8 plt.xlabel('Value')
9 plt.ylabel('Marks')
10 plt.legend()
11 plt.show()

You might also like