Мне поручено составить круговую диаграмму на основе сдавших и неуспевающих учеников. Мне интересно, есть ли способ изменить текст на круговой диаграмме. Черный цвет перекрывается неудачной частью, а белый — фоном.
импортировать случайный импорт matplotlib.pyplot как plt
def main():
students = get_students()
Student_Count = Random_Grades(students)
Total = Average (Student_Count,students)
Pie_Graph(Total,students)
def get_students():
students = int(input("How many students do you want to enter? \n Students: "))
while(students > 50):
print("The data size must be less than or equal to 50")
students = int(input("How many students do you want to enter? \n Students: "))
return students
def Random_Grades(students):
Student_Count = [([0] * 4) for i in range(students)]
for a in range(students):
for b in range(4):
Student_Count[a][b] = random.randint(1,100)
return Student_Count
def Average (Student_Count,students):
total = 0
Total = [] # will put the Total in final row
for a in range (students):
for b in range(4):
total += Student_Count [a][b]
Average = total/4
Total.append(Average) # will put the total value in the Total list
total = 0
return Total
def Pie_Graph(Total,students):
b = 0
c = 0
for a in range (students):
if Total[a] >= 60:
b += 1
elif Total[a] < 60:
c += 1
values=[b,c]
slice_labels=(['Pass','Fail'])
explode = [0.05,0.05]
plt.pie(values, labels=slice_labels, colors=('b','k'),autopct="%.1f%%",explode=explode,textprops={'color':"w"})
plt.title('Student Pass/Fail Chart')
plt.show()
print()
x="Y"
while(x!="N"):
main()
x=input("Press Y to continue, N to stop : ").upper()
Выход
Ожидаемый результат