# Drawing pie chart in Python

2022-07-24 15:47:43

``````# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
labels=[" waters ", " Barren land ", " Low vegetation ", " tree ", " Architecture ", " playing field ", " road "]
colors  = ["#126bae","#b7ae8f","#8cc269","#41b349","#fa7e23","#feba07"]
X=dataSet.iloc[0][2:]

fig = plt.figure()
plt.title(" Geological proportion before earthquake ")
plt.pie(X,labels=labels,colors=colors, autopct='%1.2f%%',pctdistance=0.8) # Draw a pie chart （ data , The label corresponding to the data , Keep two decimal places for the percentage ）

plt.savefig("start.png", dpi=300)
plt.show();
``````

X The numerical ：

``````# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
labels=[" waters ", " Barren land ", " Low vegetation ", " tree ", " Architecture ", " playing field ", " road "]
colors  = ["#126bae","#b7ae8f","#8cc269","#41b349","#fa7e23","#feba07"]
X=dataSet.iloc[3][2:]

fig = plt.figure()
plt.pie(X,labels=labels, colors=colors, autopct='%1.2f%%', pctdistance=0.8) # Draw a pie chart （ data , The label corresponding to the data , Keep two decimal places for the percentage ）
plt.title(" Geological proportion after earthquake ")

plt.savefig("end.png", dpi=300)
plt.show();
``````