python使用matplotlib制作精美的饼图

本文介绍了如何使用Python的matplotlib库创建美观的饼图,包括设置字体大小、标签值、颜色、突出显示、绘图区以及美化位置等步骤。文章还分享了如何调整图表的各个细节,如使用cm库进行颜色渐变,通过explode突出部分扇区,以及使用legend和tight_layout优化布局。
摘要由CSDN通过智能技术生成

成品

首先上最终成品
在这里插入图片描述

代码

图1的展示


# 重新设置字体大小
proptease = fm.FontProperties()
proptease.set_size('xx-large')
# font size include: ‘xx-small’,x-small’,'small’,'medium’,‘ large’,‘x-large’,‘xx-large’ or number, e.g. '12'
labels = 'internal operator user', 'external user', 'external quick view collection user', 'external stripping collaborator', 'internal robot user'
sizes = [62, 4048, 88, 36, 168]
colors = cm.GnBu(np.arange(len(sizes)) / len(sizes))  # colormaps: Paired, autumn, rainbow, gray,spring,Darks

explode = (0, 0.2, 0, 0, 0)  # only "explode" the 2nd slice (i.e. 'Hogs')

fig, axes = plt.subplots(figsize=(10, 4), ncols=3)  # 设置绘图区域大小
ax1, ax2, ax3 = axes.ravel()

plt.subplot(1, 3, 1)
# plt.pie(sizes, explode=explode, labels=labels, colors=colors,
#         autopct='%1.1f%%', shadow=False, startangle=90)
patches, texts = ax1.pie(sizes, explode=explode, colors=colors,
                                     shadow=False, startangle=90)
# plt.setp(autotexts, fontproperties=proptease)

# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')
ax3.axis('off')
ax3.legend(patches, labels, loc='center left')
plt.tight_layout()

sizes = [60, 4402, 92, 172, 0]
  • 17
    点赞
  • 102
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值