Chart Exercise Solutions New
Chart Exercise Solutions New
plt.show()
Program-2
#Program to display runs per over of the Indian Cricket team in T-20 match
import matplotlib.pyplot as plt
import numpy as np
run = [5, 7, 8, 0, 10, 12, 14, 3, 8, 9, 20, 12, 20,10, 8, 9, 10, 12, 10, 15]
overs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
r = np.arange(1, 21)
plt.yticks(r)
plt.show()
1
Program-3
#Program to display runs per over of the India and England Cricket team in T-20
match
import matplotlib.pyplot as plt
import numpy as np
India = [5, 7, 8, 0, 10, 12, 14, 3, 8, 9, 20, 12, 20,10, 8, 9, 10, 12, 10, 15]
England = [4, 6, 7, 9, 10, 5, 6, 7, 8, 10, 14, 15, 18, 9, 5, 6, 7, 0, 6, 10]
overs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
#xticks() is used to customize the x-axis scale so that we can have our own data
#instead of default one
plt.xticks(overs, fontsize=10)
plt.grid(True)
plt.legend(loc="upper left")
plt.show()
2
Program-4
import matplotlib.pyplot as p
p.bar(week, attend, color=['r', 'g', 'b', 'c', '#FFAA00', 'y'], width = 0.3)
p.xlabel("Weekdays", fontsize=15)
p.ylabel("Number of Students", fontsize=15)
p.title("Student attendance per day of Week", fontsize=15)
p.show()
3
Program-5
t.show()
4
# Program-6: Attendance in a week
plt.figure(figsize=(7, 7))
plt.plot(wk, attend, marker = 'o', color='red', markersize=6,
markeredgecolor='green', markerfacecolor="red", linestyle="dashdot",
label="Marks obtained")
plt.xlabel("Week days")
plt.ylabel("Attendance per day")
plt.title("Attendance in a week")
plt.grid(True)
plt.legend(loc="upper left")
plt.savefig("d:\\Attendance.png")
plt.show()
Note: color and marker can be given by combining the values. For example,
‘ro’ will determine the red color and marker, both. But we need to note that in
such case, linestyle parameter has be mentioned explicitly. Otherwise, scatter
chart will be produced. For example, in the above programme we use:
6
Chart-2
# Program-7 Analysis of runs and overs of two cricket team
#Ten overs match
#overs from 1 to 10
overs = np.arange(1, 11)
plt.figure(figsize=(6, 6))
plt.legend(loc='upper right')
plt.grid(True)
plt.savefig("d:\\Cricket.png")
plt.show()
#Program-8 chart-3 Bar chart: Marks obtained by Rohan in half yearly (Three
subjects)
8
sub = ['Hindi', 'English', 'Maths']
marks = [55, 75, 90]
plt.figure(figsize=(6, 4))
plt.bar(sub, marks, color=['g', 'y', 'c'], width=[0.2, 0.4, 0.6], hatch=['o', '-', '+'],
label=['H', 'E', 'M'])
plt.title("Marks analysis")
plt.yticks(np.arange(10, 101, 10))
plt.legend()
plt.savefig("d:\\Marks.png")
plt.show()