Python's matplotlib library implements pie charts

1. On January 11, 2022, the 29th press conference of "Zhengzhou City's New Coronavirus Epidemic Prevention and Control" was held in the Municipal Government Press Conference Hall to inform the latest progress of Zhengzhou City's new coronavirus epidemic prevention and control work. Statistics show that as of 24:00 on January 10, a total of 103 locally confirmed cases have been reported in the city (including 47 cases in Erqi District, 27 cases in Zhongyuan District, 14 cases in Guancheng District, 6 cases in High-tech Zone, 4 cases in Airport District, Jinshui District 4 cases, 1 case in Zhengdong New District) . Please use a pie chart to represent the above set of data.

import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['SimHei']

labels = ['二七区','中原区','管城区','高新区','航空港区','金水区','郑东新区']  #设置地区标签数组
nums = [0.456,0.262,0.136,0.057,0.039,0.039,0.011]   #设置各地区占比数组
colors = ['#377eb8','#4daf4a','#984ea3','#ff7f00','#de33e4','#456dad','#ff36f7'] #设置颜色数组
explode = (0.1,0.1,0.1,0.1,0.1,0.1,0.1) #设置每个扇区离开中心的距离
#绘图
plt.pie(nums,explode=explode,labels=labels,
autopct='%3.1f%%',startangle=45,shadow=True,colors=colors) 
#autopct设置扇形区域内百分比文字,stratangle起始绘制角度

plt.title('郑州市各地区本土新冠确诊病例占比')
plt.show()

        Run the legend:

Guess you like

Origin blog.csdn.net/qq_59470001/article/details/132810917