引入matplotlib.pyplot库

import matplotlib.pyplot as plt

设置图像大小为10x10

plt.figure(figsize = (10,10))

设置字体为黑体

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

设置正常显示负号

plt.rcParams['axes.unicode_minus'] = False

设置坐标轴背景色为紫色

plt.rcParams['axes.facecolor'] = '#cc00ff'

给图像加上标签

labels1 = ['计算机学院', '大数据学院', '财金学院'] labels2 = ['软件技术', '移动应用开发', '大数据技术与应用', '移动互联应用技术', '云计算技术与应用', '投资与理财', '财务管理']

定义学院人数数据

college = [2400, 900, 1000]

定义专业人数数据

major = [800, 1200, 400, 300, 200, 400, 200]

定义颜色数组

colors =['c' , 'r', 'y' , 'g' , 'gray', 'b', 'm']

绘制外环饼图

plt.pie(major,autopct = '%3.1f%%',radius = 1, pctdistance = 0.75,colors = colors, startangle = 180,textprops = {'color' : 'w'}, wedgeprops= { 'width':0.4, 'edgecolor':'w'})

绘制内环饼图

plt.pie(college,autopct = '%3.1f%%',radius = 0.6,pctdistance = 0.6, colors = colors,startangle = 180,textprops = {'color' : 'w'}, wedgeprops = {'width': 0.4, 'edgecolor' : 'w'})

添加图例

plt.legend(labels2,fontsize = 10,title ='专业列表', bbox_to_anchor =(1,0.6) ,loc='center left') plt.legend(labels1,fontsize = 12,title ='学院列表', bbox_to_anchor =(1,0.9) ,loc='center left')

添加标题

plt.title('2020年某大学三大学院各专业招生人数', fontsize=20)

显示图像

plt.show()

2020年某大学三大学院各专业招生人数嵌套饼图可视化

原文地址: https://www.cveoy.top/t/topic/nDTw 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录