from pyecharts.charts import Pie
from pyecharts import options as opts
import random


# 随机颜色生成
def randomcolor(kind):
    colors = []
    for i in range(kind):
        colArr = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
        color = ""
        for i in range(6):
            color += colArr[random.randint(0, 14)]
        colors.append("#" + color)
    return colors


# 数据
provinces = ['西藏', '青海', '贵州', '江苏', '新疆', '内蒙古', '海南',
             '吉林', '重庆', '山西', '安徽', '江西', '河北', '湖南', '宁夏', '河南', '云南', '湖北']
num = [51, 44, 33, 31, 31, 31, 30, 26, 25, 25, 23, 22, 22, 22, 17, 9, 4, 3]
color_series = randomcolor(len(provinces))

# 创建饼图
fig = Pie(init_opts=opts.InitOpts(width='700px', height='900px'))
# 添加数据
fig.add("", [list(z) for z in zip(provinces, num)],
        radius=['30%', '135%'],
        center=['50%', '65%'],
        rosetype='area')
# 设置全局配置
fig.set_global_opts(title_opts=opts.TitleOpts(title='南丁格尔玫瑰图'),
                    legend_opts=opts.LegendOpts(is_show=False)

                    )

# 设置系列配置和颜色
fig.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='inside', font_size=12,
                                              formatter='{b}:{c}天', font_style='italic', font_weight='bold',
                                              font_family='Microsoft YaHei')) # b:province;c:num
fig.set_colors(color_series)

# 在网页生成照片
fig.render('南丁格尔玫瑰图.html')


【Python绘图】pyecharts绘制南丁格尔玫瑰图_python学习

参考:
https://blog.csdn.net/Zzh1110/article/details/105017260
https://www.bilibili.com/video/BV1u7411Z7LX