引入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 = ['软件技术', '移动应用开发', '大数据技术与应用', '移动互联应用技术', '云计算技术与应用', '投资与理财', '财务管理']

定义各专业招生人数

data = [[800, 1200, 0], [0, 0, 900], [0, 300, 200], [0, 0, 400], [0, 0, 200], [0, 0, 0], [0, 0, 200]]

定义颜色数组

colors1 = ['#ff9999', '#66b3ff', '#99ff99'] colors2 = ['#ffcc99', '#ffb3e6', '#b3b3ff', '#ccff99', '#ffeb99', '#ffff99', '#99ffe6']

绘制外环饼图

plt.pie([sum(i) for i in data], autopct='%3.1f%%', radius=1, pctdistance=0.87, colors=colors1, startangle=180, textprops={'color': 'w'}, wedgeprops={'width': 0.25, 'edgecolor': 'w'})

绘制内环饼图

for i in range(3): plt.pie(data[i], autopct='%3.1f%%', radius=0.7 - i * 0.15, pctdistance=0.82, colors=colors2, startangle=180, textprops={'color': 'w'}, wedgeprops={'width': 0.1, 'edgecolor': 'w'})

添加图例

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

添加标题

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

显示图像

plt.show(

在这个代码基础上:# 引入matplotlibpyplot库import matplotlibpyplot as plt# 设置图像大小为10x10pltfigurefigsize = 1010# 设置字体为黑体pltrcParamsfontsans-serif = SimHei# 设置正常显示负号pltrcParamsaxesunicode_minus = False# 设置坐标轴背景色为紫色p

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

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