python中pyecharts绘制饼图

您所在的位置:网站首页 怎么绘制扇形 python中pyecharts绘制饼图

python中pyecharts绘制饼图

#python中pyecharts绘制饼图| 来源: 网络整理| 查看: 265

pyecharts包绘制饼图需要调用Pie

from pyecharts import Pie

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:所有扇区圆心角相同,仅通过半径展现数据大小

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

https://cloud.tencent.com/developer/article/1330784



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3