引入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'

给图像加上标签

labels = ['A','B','C', 'D', '其他']

定义笔记本电脑市场份额数据

laptop = [0.45,0.25,0.15,0.05,0.10]

定义pc电脑市场份额数据

pc = [0.35,0.35,0.08,0.07,0.15]

定义颜色数组

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

绘制外环饼图

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

绘制内环饼图

plt.pie(pc,autopct = '%3.1f%%',radius = 0.7,pctdistance = 0.82, colors = colors,startangle = 180,textprops = {'color' : 'w'}, wedgeprops = {'width': 0.25, 'edgecolor' : 'w'})

添加图例

plt.legend(labels,fontsize = 12,title ='公司列表', bbox_to_anchor =(1,0.6) ,loc='center left')

添加标题

plt.title('2017年笔记本(外环)及Pc电脑(内环)市场份额', fontsize=20)

显示图像

plt.show(

对以下代码进行注释:import matplotlibpyplot as pltpltfigurefigsize = 1010pltrcParams fontsans-serif= SimHeipltrcParamsaxesunicode_minus = FalsepltrcParams axesfacecolor= #cc00fflabels = ABC D 其他laptop =04502501

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

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