Ejemplo n.º 1
0
 def pyechart_Sunburst_plot(self, filedata, para):
     from pyecharts.charts import Sunburst
     file_name = '旭日图.html'
     path_plotly = self.path_dir_plotly_html + os.sep + file_name  # 文件路径,前面是文件夹后面是文件名
     costumeTheme = self.themedict[para['theme']]
     # -----------------------------------------------------------------------
     df = pd.read_excel(filedata, sheet_name='Sheet1')
     dic = self.Tree_dict(df)
     sunburst = (
         Sunburst(init_opts=opts.InitOpts(theme=costumeTheme,
                                          width=para['width'],
                                          height=para['height'])
                  )  # costumeTheme=self.themedict[para['theme']]
         .add(series_name="", data_pair=dic, radius=[
             0, "90%"
         ]).set_global_opts(
             title_opts=opts.TitleOpts(title=para["title"],
                                       subtitle=para["subtitle"]),
             toolbox_opts=opts.ToolboxOpts(feature=opts.ToolBoxFeatureOpts(
                 save_as_image=opts.ToolBoxFeatureSaveAsImageOpts(
                     background_color="white"))),
             #visualmap_opts=opts.VisualMapOpts(),
         ).set_series_opts(label_opts=opts.LabelOpts(
             is_show=True,
             color=para["color"],
             position="inside",
             font_size=para["font_size"],
             font_family=para["font_family"])).render(path_plotly))
     return path_plotly  # 返回该HTML文件路径
Ejemplo n.º 2
0
def sunburst_base(company) -> Sunburst:
    units = company.units
    charttitle = company.company

    sunburst_item_list = []
    for each in Credit_Info.objects.filter(company_id=company.id):
        sunburstitem = SunburstItem(
            name=each.bank,
            value=each.credit,
            itemstyle_opts={"color": randomcolor()},
            children=[
                SunburstItem(name="已用",
                             value=each.used,
                             itemstyle_opts={"color": randomcolor()}),
                SunburstItem(name="未用",
                             value=(each.credit - each.used),
                             itemstyle_opts={"color": randomcolor()}),
            ])
        sunburst_item_list.append(sunburstitem)

    c = (Sunburst().add("",
                        sunburst_item_list,
                        radius=[0, "95%"],
                        highlight_policy="ancestor",
                        sort_="null",
                        levels=[
                            {},
                            {
                                "r0": "10%",
                                "r": "76%",
                                "itemStyle": {
                                    "borderWidth": 2
                                },
                                "label": {
                                    "rotate": "radial"
                                },
                            },
                            {
                                "r0": "76%",
                                "r": "80%",
                                "label": {
                                    "align": "right",
                                    "position": "outside",
                                    "silent": False
                                },
                                "itemStyle": {
                                    "borderWidth": 3
                                },
                            },
                        ]).set_global_opts(title_opts=opts.TitleOpts(
                            title=charttitle,
                            subtitle="[单位:%s]" % units,
                            subtitle_textstyle_opts={
                                "font_weight": "bold",
                                "color": "#000000"
                            })).set_series_opts(label_opts=opts.LabelOpts(
                                formatter="{b}")).dump_options_with_quotes())
    return c
Ejemplo n.º 3
0
 def sunburst_base(self) -> Sunburst:
     start = datetime.datetime.now()
     data = self.get_sunburst_data()
     c = (Sunburst().add(
         series_name="", data_pair=data,
         radius=[0, "90%"]).set_series_opts(label_opts=opts.LabelOpts(
             formatter="{b}")).dump_options_with_quotes())
     end = datetime.datetime.now()
     print("Sunburst: " + str(end - start))
     return c
Ejemplo n.º 4
0
def sunburst_base(data) -> Sunburst:
    sunburst = (
        Sunburst(init_opts=opts.InitOpts(width="1000px", height="600px"))
        .add(
            series_name="", 
            data_pair=data, 
            radius=[0, "90%"])
        .set_series_opts(
            label_opts=opts.LabelOpts(formatter="{b}"
            )
        )
    )
    return sunburst
Ejemplo n.º 5
0
def sunburst(data) -> Sunburst:
    c = (
        Sunburst(init_opts=opts.InitOpts(width="900px", height="900px", bg_color=colors[-1]))
        .add(
            "",
            data_pair=data,
            highlight_policy='descendant',
            label_opts=opts.LabelOpts(rotate='radial', font_size=14, color=colors[-1]),
            itemstyle_opts=opts.ItemStyleOpts(border_color=colors[-1], border_width=2),
            sort_=JsCode("""function (a, b){
                        if (a.depth <= 2){
                            return b.getValue() - a.getValue();
                        }
                        else{
                            return b.dataIndex - a.dataIndex;
                        }
                    }"""),
            levels=[
                {},
                {
                    'r0': '0',
                    'r': '60',
                    'label': {'rotate': '0'}
                },
                {
                    'r0': '60',
                    'r': '160'
                },
                {
                    'r0': '175',
                    'r': '210',
                    'itemStyle': {'shadowBlur': '2', 'shadowColor': colors[2], 'color': 'transparent'},
                    'label': {'rotate': 'tangential', 'fontSize': '12'}
                },
                {
                    'r0': '210',
                    'r': '215',
                    'itemStyle': {'shadowBlur': '80', 'shadowColor': colors[0]},
                    'label': {'position': 'outside', 'textShadowBlur': '5', 'textShadowColor': '#333'},
                    'downplay': {'label': {'opacity': '0.2'}}
                }
            ]
        )
        .set_global_opts(title_opts=opts.TitleOpts(title="Film_records_Sunburst",
                                                   title_textstyle_opts=opts.TextStyleOpts(
                                                       color=colors[-2]
                                                   )
                        )
        )
    )
    return c
Ejemplo n.º 6
0
 def export_sunburst_city(
         data: dict,
         image_result_save_path: str = "./sunburst_city.html"
 ) -> pathlib.Path:
     """
     导出城市分布图
     """
     image = (
         Sunburst(init_opts=opts.InitOpts(width="1000px",
                                          height="600px"))  # 设定画布长宽
         .add(
             "",
             data_pair=format_sunburst_city(data),  # 载入数据
             highlight_policy="ancestor",
             radius=[0, "95%"],
             sort_="null",
             levels=[
                 {},  # 第一圈样式,如果有国家的话就不会空着
                 {
                     "r0": "15%",
                     "r": "45%",
                     "itemStyle": {
                         "borderWidth": 2
                     },
                     "label": {
                         "rotate": "tangential"
                     },
                 },  # 第二圈样式,对标省
                 {
                     "r0": "35%",
                     "r": "70%",
                     "label": {
                         "position": "outside",
                         "padding": 3,
                         "silent": False
                     },
                     "itemStyle": {
                         "borderWidth": 1
                     },
                 },  # 最外圈样式,对标市
             ],
         )
         # 设定标题
         .set_global_opts(title_opts=opts.TitleOpts(
             title="Sunburst-城市分布")).set_series_opts(
                 label_opts=opts.LabelOpts(formatter="{b}"))  # 设定名称
     )
     path = image.render(image_result_save_path)
     success(f"make city sunburst: {path}")
     return pathlib.Path(path)
def sunburst_base() -> Sunburst:
    data = [
        opts.SunburstItem(
            name="Grandpa",
            children=[
                opts.SunburstItem(
                    name="Uncle Leo",
                    value=15,
                    children=[
                        opts.SunburstItem(name="Cousin Jack", value=2),
                        opts.SunburstItem(
                            name="Cousin Mary",
                            value=5,
                            children=[opts.SunburstItem(name="Jackson", value=2)],
                        ),
                        opts.SunburstItem(name="Cousin Ben", value=4),
                    ],
                ),
                opts.SunburstItem(
                    name="Father",
                    value=10,
                    children=[
                        opts.SunburstItem(name="Me", value=5),
                        opts.SunburstItem(name="Brother Peter", value=1),
                    ],
                ),
            ],
        ),
        opts.SunburstItem(
            name="Nancy",
            children=[
                opts.SunburstItem(
                    name="Uncle Nike",
                    children=[
                        opts.SunburstItem(name="Cousin Betty", value=1),
                        opts.SunburstItem(name="Cousin Jenny", value=2),
                    ],
                )
            ],
        ),
    ]

    c = (
        Sunburst()
        .add(series_name="", data_pair=data, radius=[0, "90%"])
        .set_global_opts(title_opts=opts.TitleOpts(title="Sunburst-基本示例"))
        .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}"))
    )
    return c
Ejemplo n.º 8
0
def sunburst_official(json_file) -> Sunburst:
    f = open(json_file, 'r', encoding='utf-8')
    j = json.load(f)

    c = (Sunburst(
        init_opts=opts.InitOpts(width="4000px", height="2400px")).add(
            "",
            data_pair=j,
            highlight_policy="ancestor",
            radius=[0, "95%"],
            sort_="null",
            levels=[
                {},
                {
                    "r0": "5%",
                    "r": "35%",
                    "itemStyle": {
                        "borderWidth": 2
                    },
                    "label": {
                        "fontSize": 35
                    },
                },
                {
                    "r0": "35%",
                    "r": "70%",
                    "label": {
                        "align": "right",
                        "fontSize": 32
                    }
                },
                {
                    "r0": "70%",
                    "r": "72%",
                    "label": {
                        "position": "outside",
                        "silent": False,
                        "fontSize": 10
                    },
                    "itemStyle": {
                        "borderWidth": 3
                    },
                },
            ],
        ).set_global_opts(title_opts=opts.TitleOpts(
            title="Sunburst-meal80K")).set_series_opts(
                label_opts=opts.LabelOpts(formatter="{b}")))
    return c
Ejemplo n.º 9
0
def sunburst_official() -> Sunburst:
    with open(os.path.join("fixtures", "drink.json"), "r",
              encoding="utf-8") as f:
        j = json.load(f)

    c = (Sunburst(init_opts=opts.InitOpts(width="1000px", height="600px")).add(
        "",
        data_pair=j,
        highlight_policy="ancestor",
        radius=[0, "95%"],
        sort_="null",
        levels=[
            {},
            {
                "r0": "15%",
                "r": "35%",
                "itemStyle": {
                    "borderWidth": 2
                },
                "label": {
                    "rotate": "tangential"
                },
            },
            {
                "r0": "35%",
                "r": "70%",
                "label": {
                    "align": "right"
                }
            },
            {
                "r0": "70%",
                "r": "72%",
                "label": {
                    "position": "outside",
                    "padding": 3,
                    "silent": False
                },
                "itemStyle": {
                    "borderWidth": 3
                },
            },
        ],
    ).set_global_opts(title_opts=opts.TitleOpts(
        title="Sunburst-官方示例")).set_series_opts(label_opts=opts.LabelOpts(
            formatter="{b}")))
    return c
Ejemplo n.º 10
0
def sunburst_official() -> Sunburst:
    with open("./data/sun_data.json", "r", encoding="utf-8") as f:
        data = json.load(f)

    sun_map = (
        Sunburst(init_opts=opts.InitOpts(width="1000px", height="600px"))
        .add(
            "",
            data_pair=data,  # 数据Sequence
            highlight_policy="ancestor",  # 当鼠标移动到一个扇形块时,可以高亮相关的扇形块。
                                          # 'ancestor':高亮该扇形块和祖先元素
            radius=[0, "95%"],  # 图的半径,第一项是内半径,第二项是外半径
            sort_="null",  # # 扇形块根据数据 value 的排序方式,
                           # 如果未指定 value,则其值为子元素 value 之和。
                           # 'null':表示不排序,使用原始数据的顺序
            levels=[    # 图多层级配置
                {},
                {
                    "r0": "15%",
                    "r": "35%",
                    "itemStyle": {"borderWidth": 2},
                    "label": {"rotate": "tangential"},
                },
                {"r0": "35%", "r": "70%", "label": {"align": "right"}},
                {
                    "r0": "70%",
                    "r": "72%",
                    "label": {"position": "outside", "padding": 3, "silent": False},
                    "itemStyle": {"borderWidth": 3},
                },
            ],
        )
        .set_global_opts(title_opts=opts.TitleOpts(title="Sunburst-示例"))
            # 标签内容格式器,支持字符串模板和回调函数两种形式,
            # 字符串模板与回调函数返回的字符串均支持用 \n 换行。
            # 示例:formatter: '{b}: {@score}' .  参考官网
        .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}"))
    )
    sun_map.render('./data/sun_map.html')
Ejemplo n.º 11
0
def get_sun_data(request):
    sun_choice = request.GET.get("sun-choice")
    street = Street.objects.get(name=sun_choice)
    sun_data = []
    statuses = Achieve.objects.all()
    type_list = Type.objects.all()
    for status in statuses:
        type_value = {}
        for v in type_list:
            type_value.update({v.name: 0})

        events = status.event.get_queryset()

        for event in events:
            if event.community.street != street:
                continue
            type_value[event.type.name] += 1

        time_list = []
        for key in type_value.keys():
            if type_value[key]:
                single = opts.SunburstItem(name=key, value=type_value[key])
                time_list.append(single)

        if len(time_list):
            name = status.name
            s_item = opts.SunburstItem(name=name, children=time_list)
            sun_data.append(s_item)

    start = datetime.datetime.now()
    data = sun_data
    c = (Sunburst().add(
        series_name="", data_pair=data,
        radius=[0, "90%"]).set_series_opts(label_opts=opts.LabelOpts(
            formatter="{b}")).dump_options_with_quotes())
    end = datetime.datetime.now()
    print("Sunburst: " + str(end - start))
    return HttpResponse(c, content_type='application/json')
Ejemplo n.º 12
0
def sunburst_base() -> Sunburst:
    data = [
        opts.SunburstItem(
            name="云顶书院",
            children=[
                opts.SunburstItem(
                    name="大数据学院",
                    value=15,
                    children=[
                        opts.SunburstItem(name="Cousin Jack", value=2),
                        opts.SunburstItem(
                            name="Cousin Mary",
                            value=5,
                            children=[opts.SunburstItem(name="Jackson", value=2)],
                        ),
                        opts.SunburstItem(name="Cousin Ben", value=4),
                    ],
                ),
                opts.SunburstItem(
                    name="机械学院",
                    value=10,
                    children=[
                        opts.SunburstItem(name="Me", value=5),
                        opts.SunburstItem(name="Brother Peter", value=1),
                    ],
                ),
            ],
        ),
    ]

    c = (
        Sunburst(init_opts=opts.InitOpts(width="1000px", height="600px"))
            .add(series_name="", data_pair=data, radius=[0, "90%"])
            .set_global_opts(title_opts=opts.TitleOpts(title="Sunburst-基本示例"))
            .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}"))
    )
    return c
c = (Sunburst(init_opts=opts.InitOpts(width="1000px", height="600px")).add(
    "",
    data_pair=data,
    highlight_policy="ancestor",
    radius=[0, "95%"],
    sort_="null",
    levels=[
        {},
        {
            "r0": "15%",
            "r": "35%",
            "itemStyle": {
                "borderWidth": 2
            },
            "label": {
                "rotate": "tangential"
            },
        },
        {
            "r0": "35%",
            "r": "70%",
            "label": {
                "align": "right"
            }
        },
        {
            "r0": "70%",
            "r": "72%",
            "label": {
                "position": "outside",
                "padding": 3,
                "silent": False
            },
            "itemStyle": {
                "borderWidth": 3
            },
        },
    ],
).set_global_opts(title_opts=opts.TitleOpts(
    title="Sunburst-官方示例")).set_series_opts(label_opts=opts.LabelOpts(
        formatter="{b}")).render("Drink_flavors.html"))
Ejemplo n.º 14
0
def gender_direction() -> Sunburst:
    directions = ['开发', '设计', '秘书处']
    genders = ['男', '女']
    directionList = []
    for i in directions:
        Dname = i
        Dvalue = Freshman.objects.filter(direction=Dname)
        genderList = []
        for j in genders:
            r = str(random.randint(0, 255))
            g = str(random.randint(0, 255))
            b = str(random.randint(0, 255))
            Gvalue = Dvalue.filter(gender=j)
            genderList.append(
                opts.SunburstItem(
                    name=j,
                    value=len(Gvalue),
                    itemstyle_opts=opts.ItemStyleOpts(
                        color="rgb({0},{1},{2})".format(r, g, b))), )
        r = str(random.randint(0, 255))
        g = str(random.randint(0, 255))
        b = str(random.randint(0, 255))
        directionList.append(
            opts.SunburstItem(name=i,
                              value=len(Dvalue),
                              children=genderList,
                              itemstyle_opts=opts.ItemStyleOpts(
                                  color="rgb({0},{1},{2})".format(r, g, b))))
    data = [opts.SunburstItem(name="云顶书院", children=directionList)]
    c = (Sunburst(init_opts=opts.InitOpts(width="1000px", height="600px")).add(
        series_name="",
        data_pair=data,
        radius=[0, "90%"],
        levels=[
            {},
            {
                "r0": "15%",
                "r": "35%",
                "itemStyle": {
                    "borderWidth": 2
                },
                "label": {
                    "rotate": "tangential"
                },
            },
            {
                "r0": "35%",
                "r": "70%",
                "label": {
                    "align": "right"
                }
            },
            {
                "r0": "70%",
                "r": "72%",
                "label": {
                    "position": "outside",
                    "padding": 3,
                    "silent": False
                },
                "itemStyle": {
                    "borderWidth": 3
                },
            },
        ],
    ).set_global_opts(title_opts=opts.TitleOpts(title="学院专业")).set_series_opts(
        label_opts=opts.LabelOpts(formatter="{b}")))
    return c
Ejemplo n.º 15
0
def major_academy() -> Sunburst:
    colleges = Academy.objects.all()
    collegeList = []
    for i in range(0, len(colleges)):
        Aname = colleges[i].academy
        Avalue = Freshman.objects.filter(college=Aname)
        majors = Major.objects.filter(majorAcademy_id=colleges[i].id)
        majorList = []
        for j in range(0, len(majors)):
            Mname = majors[j].major
            Mvalue = Avalue.filter(major=Mname)
            r = str(random.randint(0, 255))
            g = str(random.randint(0, 255))
            b = str(random.randint(0, 255))
            majorList.append(
                opts.SunburstItem(
                    name=Mname,
                    value=len(Mvalue),
                    itemstyle_opts=opts.ItemStyleOpts(
                        color="rgb({0},{1},{2})".format(r, g, b))))  # 专业数据
        r = str(random.randint(0, 255))
        g = str(random.randint(0, 255))
        b = str(random.randint(0, 255))
        collegeList.append(
            opts.SunburstItem(
                name=Aname,
                value=len(Avalue),
                children=majorList,
                itemstyle_opts=opts.ItemStyleOpts(
                    color="rgb({0},{1},{2})".format(r, g, b))))  # 学院数据
    data = [opts.SunburstItem(name="云顶书院", children=collegeList)]
    c = (Sunburst(init_opts=opts.InitOpts(width="1000px", height="600px")).add(
        series_name="",
        data_pair=data,
        radius=[0, "90%"],
        levels=[
            {},
            {
                "r0": "15%",
                "r": "35%",
                "itemStyle": {
                    "borderWidth": 2
                },
                "label": {
                    "rotate": "tangential"
                },
            },
            {
                "r0": "35%",
                "r": "70%",
                "label": {
                    "align": "right"
                }
            },
            {
                "r0": "70%",
                "r": "72%",
                "label": {
                    "position": "outside",
                    "padding": 3,
                    "silent": False
                },
                "itemStyle": {
                    "borderWidth": 3
                },
            },
        ],
    ).set_global_opts(title_opts=opts.TitleOpts(title="学院专业")).set_series_opts(
        label_opts=opts.LabelOpts(formatter="{b}")))
    return c
def test_sunburst_base(fake_writer):
    data = [
        {
            "name":
            "Grandpa",
            "children": [
                {
                    "name":
                    "Uncle Leo",
                    "value":
                    15,
                    "children": [
                        {
                            "name": "Cousin Jack",
                            "value": 2
                        },
                        {
                            "name": "Cousin Mary",
                            "value": 5,
                            "children": [{
                                "name": "Jackson",
                                "value": 2
                            }],
                        },
                        {
                            "name": "Cousin Ben",
                            "value": 4
                        },
                    ],
                },
                {
                    "name":
                    "Father",
                    "value":
                    10,
                    "children": [
                        {
                            "name": "Me",
                            "value": 5
                        },
                        {
                            "name": "Brother Peter",
                            "value": 1
                        },
                    ],
                },
            ],
        },
        {
            "name":
            "Nancy",
            "children": [{
                "name":
                "Uncle Nike",
                "children": [
                    {
                        "name": "Cousin Betty",
                        "value": 1
                    },
                    {
                        "name": "Cousin Jenny",
                        "value": 2
                    },
                ],
            }],
        },
    ]

    c = Sunburst().add("Sunburst 演示数据", data)
    c.render()
    _, content = fake_writer.call_args[0]
    eq_(c.theme, "white")
    eq_(c.renderer, "canvas")
Ejemplo n.º 17
0
        city_dict["name"]=city
        #city_dict["itemStyle"]= {"color": "#d0545f"}
        values=dict(city_data["质量等级"].value_counts())
        sum=0
        for name,value in zip(values.keys(),values.values()):
            k={}
            if "污染" in name:
                #sum+=int(value)
                k["itemStyle"]={"color":"red"}
            if "良" in name:
                k["itemStyle"] = {"color": "orange"}
            if "优" in name:
                k["itemStyle"] = {"color": "green"}
            k["name"]=name
            k["value"]=int(value)
            #k["itemStyle"] = {"color": "#d0545f"}
            childern.append(k)
        city_dict["children"]=childern
        #city_dict["value"]=sum
        data.append(city_dict)
    print(data)
    sun=(
        Sunburst(init_opts=opts.InitOpts("1000px", height="600px"))
        .add("空气质量",data_pair=data)
        .set_global_opts(title_opts=opts.TitleOpts(title="{}年空气质量".format(i)))

    )
    tl.add(sun, "{}年".format(i))
tl.render("Aqi数据.html")

'''Bar: Bar_histogram_color'''
'''Line: 
Line_connect_null
Line_color_with_js_func
Distribution_of_electricity
'''

##=============================================================================================##
##=============================================================================================##
##============================= 极坐标系:饼图Pie、旭日图Sunburst =============================##
##=============================================================================================##
##=============================================================================================##

#---------------------------------------- 定义及添加数据 ----------------------------------------#
sunburst=(
    Sunburst()
    .add(
        # 名称
        'name',
        
        # 数据
        data_pair=[
            {'name':'a','children':[data_pair2]},
            {'name':'a','value':1},
        ],
    )
    
    # 标题
    .set_global_opts(title_opts=opts.TitleOpts(title="示例"))
    
    # 标签
Ejemplo n.º 19
0
        try:
            fill_color(elm['children'], color)
        except:
            pass
        elm['itemStyle'] = dict(color=color)


fill_color(data[1], "#aaaaaa")
fill_color(data[0], "#ca8622")
fill_color(data[0]['children'][0], "#c23531")
fill_color(data[0]['children'][1], "#2f4554")
fill_color(data[0]['children'][2], "#61a0a8")
fill_color(data[0]['children'][3], "#d48265")
fill_color(data[0]['children'][4], "#749f83")

SAVE = True
if SAVE:
    c = (Sunburst(init_opts=opts.InitOpts(width="1000px", height="600px")).add(
        "",
        data_pair=data,
        highlight_policy="ancestor",
        radius=[0, "95%"],
        sort_="asc",
    ).set_global_opts(title_opts=opts.TitleOpts(
        title="Total Number of Sales by Categories \n(Top 5 and others)")).
         set_series_opts(
             label_opts=opts.LabelOpts(is_show=False, formatter="{b}")).render(
                 os.path.join(output_path, "html_files",
                              "top5_other_categories.html")))
print('done')
Ejemplo n.º 20
0
    def analyseSignatureEmotion(self):
        signatures = self.df_friends[['Sex', 'Signature']]
        neutral = {
            "name":
            "中性",
            "itemStyle": {
                "color": self.createRandomColor()
            },
            "children": [{
                "name": "男",
                "itemStyle": {
                    "color": self.createRandomColor()
                },
                "children": []
            }, {
                "name": "女",
                "itemStyle": {
                    "color": self.createRandomColor()
                },
                "children": []
            }, {
                "name": "未设置",
                "itemStyle": {
                    "color": self.createRandomColor()
                },
                "children": []
            }]
        }
        position = {
            "name":
            "积极",
            "itemStyle": {
                "color": self.createRandomColor()
            },
            "children": [{
                "name": "男",
                "itemStyle": {
                    "color": self.createRandomColor()
                },
                "children": []
            }, {
                "name": "女",
                "itemStyle": {
                    "color": self.createRandomColor()
                },
                "children": []
            }, {
                "name": "未设置",
                "itemStyle": {
                    "color": self.createRandomColor()
                },
                "children": []
            }]
        }
        negative = {
            "name":
            "消极",
            "itemStyle": {
                "color": self.createRandomColor()
            },
            "children": [{
                "name": "男",
                "itemStyle": {
                    "color": self.createRandomColor()
                },
                "children": []
            }, {
                "name": "女",
                "itemStyle": {
                    "color": self.createRandomColor()
                },
                "children": []
            }, {
                "name": "未设置",
                "itemStyle": {
                    "color": self.createRandomColor()
                },
                "children": []
            }]
        }
        unset = {
            "name":
            "空",
            "itemStyle": {
                "color": self.createRandomColor()
            },
            "children": [{
                "name": "男",
                "itemStyle": {
                    "color": self.createRandomColor()
                },
                "children": []
            }, {
                "name": "女",
                "itemStyle": {
                    "color": self.createRandomColor()
                },
                "children": []
            }, {
                "name": "未设置",
                "itemStyle": {
                    "color": self.createRandomColor()
                },
                "children": []
            }]
        }
        for sex, signature in signatures.values:
            sex = str(sex)
            signature = str(signature)
            dictemp = {
                "name": signature if signature != 'nan' else '空',
                "value": 1,
                "itemStyle": {
                    "color": self.createRandomColor()
                },
            }
            if signature == 'nan':
                self.putEmotiomInSex(sex, unset['children'], dictemp)
            else:
                e = SnowNLP(signature).sentiments
                if (e > 0.5):
                    self.putEmotiomInSex(sex, position['children'], dictemp)
                elif (e < 0.5):
                    self.putEmotiomInSex(sex, negative['children'], dictemp)
                else:
                    self.putEmotiomInSex(sex, neutral['children'], dictemp)
        lst = [position, negative, neutral, unset]

        sun = (Sunburst(init_opts=opts.InitOpts()).add(
            "",
            data_pair=lst,
            highlight_policy="ancestor",
            radius=[0, "95%"],
            sort_="null",
            levels=[
                {},
                {
                    "r0": "15%",
                    "r": "35%",
                    "itemStyle": {
                        "borderWidth": 2
                    },
                    "label": {
                        "rotate": "tangential"
                    },
                },
                {
                    "r0": "35%",
                    "r": "70%",
                    "label": {
                        "align": "right"
                    }
                },
                {
                    "r0": "70%",
                    "r": "72%",
                    "label": {
                        "position": "outside",
                        "padding": 3,
                        "silent": False,
                        "show": False
                    },
                    "itemStyle": {
                        "borderWidth": 3
                    },
                },
            ],
        ).set_global_opts(title_opts=opts.TitleOpts(
            title="签名情感与性别分析")).set_series_opts(label_opts=opts.LabelOpts(
                formatter="{b}")))
        return sun
Ejemplo n.º 21
0
        animation_easing="cubicOut",  # 初始动画的缓动效果
        animation_delay=0,  # 初始动画的延迟
        animation_duration_update=300,  # 数据更新动画的时长
        animation_easing_update="cubicOut",  # 数据更新动画的缓动效果
        animation_delay_update=300)  # 数据更新动画的延迟

    myOpts = InitOpts(width="1600px",
                      height="800px",
                      chart_id="myfirstchart",
                      renderer=RenderType.CANVAS,
                      page_title="firstchart",
                      theme="white",
                      bg_color=None,
                      animation_opts=myAni)

    mysunburst = Sunburst(init_opts=myOpts)

    conn = sqlite3.connect('pdftables.sqlite')
    cur = conn.cursor()

    c = cur.execute("select * from company_info")
    companyinfo = c.fetchone()
    charttitle = companyinfo[1]
    units = companyinfo[2]

    c = cur.execute(
        "select bank, credit, used from credit_info where company = '%d'" %
        companyinfo[0])
    creditinfo = c.fetchall()
    conn.close()
    myitemlist = []
Ejemplo n.º 22
0
# %% [markdown]
# ### Sankey

with open("data/energy.json") as j:
    data = json.load(j)
sankey = Sankey()
sankey.add("", nodes=data["nodes"], links=data["links"])
sankey.render_notebook()

# %% [markdown]
# ### Sunburst

with open("data/drink_flavors.json") as f:
    data = json.load(f)
sunburst = Sunburst()
sunburst.add("", data)
sunburst.render_notebook()
# sunburst.render("output/sunburst.html")

# %% [markdown]
# ### Graph -- 关系图

import itertools as itl
nodes = [{
    "name": "N1",
    "symbolSize": 1
}, {
    "name": "N2",
    "symbolSize": 2
}, {
Ejemplo n.º 23
0
                name="Father",
                value=10,
                children=[
                    opts.SunburstItem(name="Me", value=5),
                    opts.SunburstItem(name="Brother Peter", value=1),
                ],
            ),
        ],
    ),
    opts.SunburstItem(
        name="Nancy",
        children=[
            opts.SunburstItem(
                name="Uncle Nike",
                children=[
                    opts.SunburstItem(name="Cousin Betty", value=1),
                    opts.SunburstItem(name="Cousin Jenny", value=2),
                ],
            )
        ],
    ),
]

c = (Sunburst(init_opts=opts.InitOpts(width="1000px", height="600px")).add(
    series_name="", data_pair=data, radius=[0, "90%"]).set_global_opts(
        title_opts=opts.TitleOpts(title="Sunburst-基本示例")).set_series_opts(
            label_opts=opts.LabelOpts(formatter="{b}")))

c.width = "100%"
put_html(c.render_notebook())
Ejemplo n.º 24
0
def test_sunburst_base():
    data = [
        {
            "name":
            "Grandpa",
            "children": [
                {
                    "name":
                    "Uncle Leo",
                    "value":
                    15,
                    "children": [
                        {
                            "name": "Cousin Jack",
                            "value": 2
                        },
                        {
                            "name": "Cousin Mary",
                            "value": 5,
                            "children": [{
                                "name": "Jackson",
                                "value": 2
                            }],
                        },
                        {
                            "name": "Cousin Ben",
                            "value": 4
                        },
                    ],
                },
                {
                    "name":
                    "Father",
                    "value":
                    10,
                    "children": [
                        {
                            "name": "Me",
                            "value": 5
                        },
                        {
                            "name": "Brother Peter",
                            "value": 1
                        },
                    ],
                },
            ],
        },
        {
            "name":
            "Nancy",
            "children": [{
                "name":
                "Uncle Nike",
                "children": [
                    {
                        "name": "Cousin Betty",
                        "value": 1
                    },
                    {
                        "name": "Cousin Jenny",
                        "value": 2
                    },
                ],
            }],
        },
    ]

    c = Sunburst().add("Sunburst 演示数据", data)
    eq_("white", c.theme)
    eq_("canvas", c.renderer)