Я пытаюсь создать две круговые диаграммы в одной и той же функции в python, однако кажется, что я не могу заставить вторую круговую диаграмму рисовать правильно.Является ли мой метод очистки неверным?
# Create Pie Chart Of Ethnicitys
Cols = ['g', 'y', 'c', 'm', 'r', 'b']
# Plot
plt.pie(Slices, labels=Labels, colors=Cols,
autopct='%1.1f%%', shadow=True, startangle=140)
plt.axis('equal')
plt.title("Ethnicity Scouts")
EPieChart = plt.gcf()
pylab.savefig("EthnicityPieChart.png", bbox_inches='tight')
EPieChart.savefig("EthnicityPieChart.png", bbox_inches='tight')
print("Completed")
plt.clf()
#Gender Pie Chart
# Defining Labels For Pie Chart
LabelsG = ["Male","Female","Other"]
# Defining Data Variables For Each Slice Of The Pie Chart
NoOfMale=0
NoOfFemale=0
NoOfOther=0
Male=("Male")
Female=("Female")
Other=("Other")
SlicesG = [NoOfMale,NoOfFemale,NoOfOther]
#Gather Data
if NoOfMale==0:
SlicesG.remove(NoOfMale)
LabelsG.remove("Male")
if NoOfFemale==0:
SlicesG.remove(NoOfFemale)
LabelsG.remove("Female")
if NoOfOther==0:
SlicesG.remove(NoOfOther)
LabelsG.remove("Other")
print(NoOfMale)
print(NoOfFemale)
print(NoOfOther)
# Create Pie Chart Of Gender
Cols = ['b','r','g']
# Plot
plt.pie(SlicesG, labels=LabelsG, colors=Cols,
autopct='%1.1f%%', shadow=True, startangle=140)
plt.axis('equal')
plt.title("Gender Diversity Of Scouts")
GPieChart = plt.gcf()
pylab.savefig("GenderPieChart.png", bbox_inches='tight')
GPieChart.savefig("GenderPieChart.png", bbox_inches='tight')
doc.add_picture('GenderPieChart.png', width=Inches(4.0))
print("Completed")
tk.messagebox.showinfo("Success!","Scout Census Created!")
return
Фактические результаты:
С данными: NoOfMales = 8 NoOfFemales = 1 NoOfOther

