参考文档:Pie - Pie_set_color - Document (pyecharts.org)
模板
from pyecharts import options as opts
from pyecharts.charts import Pie
from pyecharts.faker import Faker"""1-Pie() 创建Pie对象2-.add("", [list(z) for z in zip(Faker.choose(), Faker.values())])给饼状图添加元素(元素随机,系统设置为一种类型,可自己修改)3-.set_colors(["blue", "green", "yellow", "red", "pink", "orange", "purple"])给饼状图设置颜色4-.set_global_opts(title_opts=opts.TitleOpts(title="Pie-设置颜色"))给饼状图设置标题5-.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))给饼状图设置标签formatter="{b}: {c}" 表示标签显示的形式是 名称:值6-.render("pie_set_color.html")生成对应的网页文件 pie_set_color.html
"""c = (Pie().add("", [list(z) for z in zip(Faker.choose(), Faker.values())]).set_colors(["blue", "green", "yellow", "red", "pink", "orange", "purple"]).set_global_opts(title_opts=opts.TitleOpts(title="Pie-设置颜色")).set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")).render("pie_set_color.html")
)
from pyecharts import options as opts
from pyecharts.charts import Pie
from pyecharts.faker import Fakerdata=[['衬衫',138],['毛衣',40],['领带',74],['裤子',112],['风衣',147],['高跟鞋',104],['袜子',65]]c = (Pie().add("", data).set_colors(["blue", "green", "yellow", "red", "pink", "orange", "purple"]).set_global_opts(title_opts=opts.TitleOpts(title="Pie-商品销售情况"),toolbox_opts=opts.TitleOpts(is_show=True)).set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}",font_size=12)).render("pie_sale.html")
)