社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
pyecharts包绘制饼图需要调用Pie
from pyecharts import Pie
Pie.add()方法签名:
add(name, attr, value,
radius=None,
center=None,
rosetype=None, **kwargs)
1,基本饼图:
from pyecharts import Pie
attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 = [11, 12, 13, 10, 10, 10]
pie = Pie("饼图示例")
pie.add(
"",
attr,
v1,
is_label_show=True,
is_more_utils=True
)
pie.render(path="Bing1.html")
结果Bing1.html
2,环状饼图示例:
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,
is_more_utils=True,
legend_orient="vertical",
legend_pos="left",
)
pie.render(path="Bing2.html")
结果Bing2.html
3, 饼图和玫瑰图示例:
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",
is_label_show=True,
)
pie.add(
"商品B",
attr,
v2,
center=[75, 50],
is_random=True,
radius=[30, 75],
rosetype="area",
is_legend_show=False,
is_label_show=True,
# is_more_utils=True,
)
pie.render(path="Bing3.html")
结果Bing3.html
4,多个饼图示例:
from pyecharts import Pie
from pyecharts import Style
# 否则会遇到错误NameError: name 'Style' is not defined
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(path="Bing4.html")
结果Bing4.html
第一个【剧情】的legend位置比较突出,单独一行,如何才能都放在一行??
参考:
http://pyecharts.org/#/zh-cn/charts_base?id=pie%EF%BC%88%E9%A5%BC%E5%9B%BE%EF%BC%89
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!