小白学Python(11)——pyecharts,绘制饼图 Pie
Pie-基本示例
1 from example.commons import Faker 2 from pyecharts import options as opts 3 from pyecharts.charts import Page, Pie 4 5 6 pie=( 7 Pie() 8 .add("", [list(z) for z in zip(Faker.choose(), Faker.values())]) 9 .set_global_opts(title_opts=opts.TitleOpts(title="Pie-基本示例")) 10 .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")) 11 ) 12 13 pie.render('pie.html')
1 from example.commons import Faker 2 from pyecharts import options as opts 3 from pyecharts.charts import Page, Pie 4 5 6 pie=( 7 Pie() 8 .add( 9 "", 10 [list(z) for z in zip(Faker.choose(), Faker.values())], 11 radius=["40%", "75%"], 12 ) 13 .set_global_opts( 14 title_opts=opts.TitleOpts(title="Pie-Radius"), 15 legend_opts=opts.LegendOpts( 16 orient="vertical", pos_top="15%", pos_left="2%" 17 ), 18 ) 19 .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")) 20 ) 21 22 pie.render('pie.html')
1 from example.commons import Faker 2 from pyecharts import options as opts 3 from pyecharts.charts import Page, Pie 4 5 v = Faker.choose() 6 7 pie=( 8 Pie() 9 .add( 10 "", 11 [list(z) for z in zip(v, Faker.values())], 12 radius=["30%", "75%"], 13 center=["25%", "50%"], 14 rosetype="radius", 15 label_opts=opts.LabelOpts(is_show=False), 16 ) 17 .add( 18 "", 19 [list(z) for z in zip(v, Faker.values())], 20 radius=["30%", "75%"], 21 center=["75%", "50%"], 22 rosetype="area", 23 ) 24 .set_global_opts(title_opts=opts.TitleOpts(title="Pie-玫瑰图示例")) 25 ) 26 27 pie.render('pie.html')
1 from example.commons import Faker 2 from pyecharts import options as opts 3 from pyecharts.charts import Page, Pie 4 5 pie=( 6 Pie() 7 .add( 8 "", 9 [list(z) for z in zip(["剧情", "其他"], [25, 75])], 10 center=["20%", "30%"], 11 radius=[40, 60], 12 ) 13 .add( 14 "", 15 [list(z) for z in zip(["奇幻", "其他"], [24, 76])], 16 center=["55%", "30%"], 17 radius=[40, 60], 18 ) 19 .add( 20 "", 21 [list(z) for z in zip(["爱情", "其他"], [14, 86])], 22 center=["20%", "70%"], 23 radius=[40, 60], 24 ) 25 .add( 26 "", 27 [list(z) for z in zip(["惊悚", "其他"], [11, 89])], 28 center=["55%", "70%"], 29 radius=[40, 60], 30 ) 31 .set_global_opts( 32 title_opts=opts.TitleOpts(title="Pie-多饼图基本示例"), 33 legend_opts=opts.LegendOpts( 34 type_="scroll", pos_top="20%", pos_left="80%", orient="vertical" 35 ), 36 ) 37 .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")) 38 ) 39 40 pie.render('pie.html')