python draw pie chart

# -*- coding: utf-8 -*-
import numpy as np  
import matplotlib.mlab as mlab  
import matplotlib.pyplot as plt  
labels=["水域", "贫瘠土地", "低矮植被", "树木", "建筑", "运动场", "道路"]
colors  = ["#126bae","#b7ae8f","#8cc269","#41b349","#fa7e23","#feba07"]
X=dataSet.iloc[0][2:]  
 
fig = plt.figure()
plt.title("地震前地质占比")
plt.pie(X,labels=labels,colors=colors, autopct='%1.2f%%',pctdistance=0.8) #画饼图(数据,数据对应的标签,百分数保留两位小数点)
  
plt.savefig("start.png", dpi=300)
plt.show();

Value of X:
insert image description here

Please add a picture description

# -*- coding: utf-8 -*-
import numpy as np  
import matplotlib.mlab as mlab  
import matplotlib.pyplot as plt  
labels=["水域", "贫瘠土地", "低矮植被", "树木", "建筑", "运动场", "道路"]
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) #画饼图(数据,数据对应的标签,百分数保留两位小数点)
plt.title("地震后地质占比")
  
plt.savefig("end.png", dpi=300)
plt.show();

Please add a picture description

Guess you like

Origin blog.csdn.net/weixin_44669966/article/details/125916952