饼图主要用于表现不同类目的数据在总和中的占比。每个的弧度表示数据数量的比例。
Pie.add()
方法签名
add(name, attr, value,
radius=None,
center=None,
rosetype=None, **kwargs)
name -> str
图例名称
attr -> list
属性名称
value -> list
属性所对应的值
radius -> list
饼图的半径,数组的第一项是内半径,第二项是外半径,默认为 [0, 75]
默认设置成百分比,相对于容器高宽中较小的一项的一半
center -> list
饼图的中心(圆心)坐标,数组的第一项是横坐标,第二项是纵坐标,默认为 [50, 50]
默认设置成百分比,设置成百分比时第一项是相对于容器宽度,第二项是相对于容器高度
rosetype -> str
是否展示成南丁格尔图,通过半径区分数据大小,有'radius'和'area'两种模式。默认为'radius'
radius:扇区圆心角展现数据的百分比,半径展现数据的大小
area:所有扇区圆心角相同,仅通过半径展现数据大小
from pyecharts import Pie
attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 = [11, 12, 13, 10, 10, 10]
pie = Pie("饼图示例")
pie.add("", attr, v1, is_label_show=True)
pie.render()
from pyecharts import Pie
attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 = [11, 12, 13, 10, 10, 10]
pie = Pie("饼图-圆环图示例", title_pos='center')
pie.add(
"",
attr,
v1,
radius=[40, 75],
label_text_color=None,
is_label_show=True,
legend_orient="vertical",
legend_pos="left",
)
pie.render()
from pyecharts import Pie
attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 = [11, 12, 13, 10, 10, 10]
v2 = [19, 21, 32, 20, 20, 33]
pie = Pie("饼图-玫瑰图示例", title_pos='center', width=900)
pie.add(
"商品A",
attr,
v1,
center=[25, 50],
is_random=True,
radius=[30, 75],
rosetype="radius",
)
pie.add(
"商品B",
attr,
v2,
center=[75, 50],
is_random=True,
radius=[30, 75],
rosetype="area",
is_legend_show=False,
is_label_show=True,
)
pie.render()
饼中饼
import random
from pyecharts import Pie
attr = ['A', 'B', 'C', 'D', 'E', 'F']
pie = Pie("饼图示例", width=1000, height=600)
pie.add(
"",
attr,
[random.randint(0, 100) for _ in range(6)],
radius=[50, 55],
center=[25, 50],
is_random=True,
)
pie.add(
"",
attr,
[random.randint(20, 100) for _ in range(6)],
radius=[0, 45],
center=[25, 50],
rosetype="area",
)
pie.add(
"",
attr,
[random.randint(0, 100) for _ in range(6)],
radius=[50, 55],
center=[65, 50],
is_random=True,
)
pie.add(
"",
attr,
[random.randint(20, 100) for _ in range(6)],
radius=[0, 45],
center=[65, 50],
rosetype="radius",
)
pie.render()
多个饼图画在一张图内
from pyecharts import Pie
pie = Pie('各类电影中"好片"所占的比例', "数据来着豆瓣", title_pos='center')
style = Style()
pie_style = style.add(
label_pos="center",
is_label_show=True,
label_text_color=None
)
pie.add(
"", ["剧情", ""], [25, 75], center=[10, 30], radius=[18, 24], **pie_style
)
pie.add(
"", ["奇幻", ""], [24, 76], center=[30, 30], radius=[18, 24], **pie_style
)
pie.add(
"", ["爱情", ""], [14, 86], center=[50, 30], radius=[18, 24], **pie_style
)
pie.add(
"", ["惊悚", ""], [11, 89], center=[70, 30], radius=[18, 24], **pie_style
)
pie.add(
"", ["冒险", ""], [27, 73], center=[90, 30], radius=[18, 24], **pie_style
)
pie.add(
"", ["动作", ""], [15, 85], center=[10, 70], radius=[18, 24], **pie_style
)
pie.add(
"", ["喜剧", ""], [54, 46], center=[30, 70], radius=[18, 24], **pie_style
)
pie.add(
"", ["科幻", ""], [26, 74], center=[50, 70], radius=[18, 24], **pie_style
)
pie.add(
"", ["悬疑", ""], [25, 75], center=[70, 70], radius=[18, 24], **pie_style
)
pie.add(
"",
["犯罪", ""],
[28, 72],
center=[90, 70],
radius=[18, 24],
legend_top="center",
**pie_style
)
pie.render()