饼图绘制错误与多个图表

时间:2019-02-03 10:50:25

标签: python python-3.x matplotlib graph

我正在尝试在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

enter image description here

Pie 2

0 个答案:

没有答案