用matplotlib.pyplot绘制甜甜圈图

本文详细介绍了如何使用matplotlib.pyplot库在Python中创建美观的甜甜圈图。从数据准备到具体代码实现,一步步解析绘制过程,帮助读者掌握这一数据可视化技巧。
摘要由CSDN通过智能技术生成
# 用matplotlib绘制甜甜圈饼图
# The effect of the donut shape is achieved by setting a width to the pie's wedges through the wedgeprops argument.
%matplotlib inline  # matplotlib的图表直接嵌入到Notebook之中, 仅在jupyter notebook 或 jupyter qtconsole有用
import matplotlib.pyplot as plt
import numpy as np
# Create a figure and a set of subplots
# Returns
# fig : :class:`matplotlib.figure.Figure` object
# ax : Axes object or array of Axes objects.
#    
#        ax can be either a single :class:`matplotlib.axes.Axes` object or an
#        array of Axes objects if more than one subplot was created.
fig, ax = plt.subplots()  # 1*1画布

size = 0.3
vals = np.array([[60., 32.], [37., 40.], [29., 10.]])  # 3*2 array

cmap = plt.get_cmap("tab20c")  # Get a colormap instance, matplotlib.cm
outer_colors = cmap(np.arange(3)*4)  # cmap([0,4,8]), len(cmap.colors) -> 20
inner_colors = cmap(np
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值