Exemple #1
0
def charts():
    fp = open('./oldData.txt', 'r')

    # Timeline
    timeline = Timeline(init_opts=opts.InitOpts(
        width="1660px",
        height="708px",
    ))

    # 48 bar charts
    for i in range(48):
        X, Y, Color = getSta(fp)

        # y-axle with color
        y = []
        for j in range(22):
            y.append(
                opts.BarItem(
                    name=X[j],
                    value=Y[j],
                    itemstyle_opts=opts.ItemStyleOpts(color=Color[j])))

        # single bar chart
        bar = (
            Bar().add_xaxis(X).add_yaxis(
                "Youbike 使用率", y).reversal_axis().set_global_opts(
                    title_opts=opts.TitleOpts(
                        title="南港區Youbike的一天",
                        pos_left="center",
                    ),
                    legend_opts=opts.LegendOpts(pos_left="left"),
                    graphic_opts=[
                        opts.GraphicGroup(  # add a block
                            graphic_item=opts.GraphicItem(left="80%",
                                                          top="80%"),
                            children=[
                                opts.GraphicText(  # add text into the block
                                    graphic_item=opts.GraphicItem(
                                        left="center",
                                        top="center",
                                        # z=100
                                    ),
                                    graphic_textstyle_opts=opts.
                                    GraphicTextStyleOpts(
                                        text="{}".format(invTime[i]),
                                        font="48px Verdana",
                                    ),
                                )
                            ])
                    ]).set_series_opts(  # number showed at right of the bar
                        label_opts=opts.LabelOpts(position="right",
                                                  color="#333")))
        timeline.add(bar, "")  # add single bar chart into timeline
        timeline.add_schema(play_interval=1000,
                            is_loop_play=True)  # play settings

    # export into HTML
    timeline.render("YoubikeUsingRate.html")

    fp.close()
def draw_bar(df, date_list, tl):
    for date in date_list:
        _date = date[-5:]
        df4 = get_data(df, date)
        x = df4['country'].to_list()
        y = df4['confirmed'].to_list()

        bar = (Bar(init_opts=opts.InitOpts(
            theme=ThemeType.ROMANTIC)).add_xaxis(x).add_yaxis(
                "确诊人数", y).reversal_axis().set_series_opts(
                    label_opts=opts.LabelOpts(is_show=True,
                                              position='right'), ).
               set_global_opts(
                   legend_opts=opts.LegendOpts(is_show=True),
                   title_opts=opts.TitleOpts("{} Day".format(_date)),
                   graphic_opts=[
                       opts.GraphicGroup(
                           graphic_item=opts.GraphicItem(
                               rotation=JsCode("Math.PI / 4"),
                               bounding="raw",
                               right=100,
                               bottom=110,
                               z=100,
                           ),
                           children=[
                               opts.GraphicRect(
                                   graphic_item=opts.GraphicItem(left="center",
                                                                 top="center",
                                                                 z=100),
                                   graphic_shape_opts=opts.GraphicShapeOpts(
                                       width=400, height=50),
                                   graphic_basicstyle_opts=opts.
                                   GraphicBasicStyleOpts(
                                       fill="rgba(0,0,0,0.3)"),
                               ),
                               opts.GraphicText(
                                   graphic_item=opts.GraphicItem(left="center",
                                                                 top="center",
                                                                 z=100),
                                   graphic_textstyle_opts=opts.
                                   GraphicTextStyleOpts(
                                       text="重点国家{}日数据".format(_date),
                                       font="bold 26px Microsoft YaHei",
                                       graphic_basicstyle_opts=opts.
                                       GraphicBasicStyleOpts(fill="#fff"),
                                   ),
                               ),
                               opts.GraphicImage(
                                   graphic_item=opts.GraphicItem(left="center",
                                                                 top="center",
                                                                 z=100),
                                   graphic_imagestyle_opts=opts.
                                   GraphicImageStyleOpts(
                                       graphic_basicstyle_opts=opts.
                                       GraphicBasicStyleOpts(fill='#fff'))),
                           ],
                       )
                   ],
               ))
        tl.add(bar, "{}".format(_date))
Exemple #3
0
 def test_timeline_graphic(self):
     self.tl.add_schema(
         graphic_opts=[
             opts.GraphicGroup(
                 graphic_item=opts.GraphicItem(
                     rotation=JsCode("Math.PI / 4"),
                     bounding="raw",
                     right=110,
                     bottom=110,
                     z=100,
                 ),
                 children=[
                     opts.GraphicRect(
                         graphic_item=opts.GraphicItem(
                             left="center", top="center", z=100
                         ),
                         graphic_shape_opts=opts.GraphicShapeOpts(
                             width=400, height=50
                         ),
                         graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                             fill="rgba(0,0,0,0.3)"
                         ),
                     ),
                     opts.GraphicText(
                         graphic_item=opts.GraphicItem(
                             left="center", top="center", z=100
                         ),
                         graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                             text="pyecharts bar chart",
                             font="bold 26px Microsoft YaHei",
                             graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                 fill="#fff"
                             ),
                         ),
                     ),
                 ],
             )
         ]
     )
     eq_(
         type(opts.GraphicGroup()),
         type(self.tl.options.get("baseOption").get("timeline").get("graphic")[0]),
     )
def timelineChart(df):
    x = Faker.choose()
    tl = Timeline()
    for i in range(2015, 2020):
        bar = (
            Bar()
            .add_xaxis(x)
            .add_yaxis("商家A", Faker.values())
            .add_yaxis("商家B", Faker.values())
            .set_global_opts(
                title_opts=opts.TitleOpts("某商店{}年营业额 - With Graphic 组件".format(i)),
                toolbox_opts=opts.ToolboxOpts(), brush_opts=opts.BrushOpts(),
                graphic_opts=[
                    opts.GraphicGroup(
                        graphic_item=opts.GraphicItem(
                            rotation=JsCode("Math.PI / 4"),
                            bounding="raw",
                            right=100,
                            bottom=110,
                            z=100,
                        ),
                        children=[
                            opts.GraphicRect(
                                graphic_item=opts.GraphicItem(
                                    left="center", top="center", z=100
                                ),
                                graphic_shape_opts=opts.GraphicShapeOpts(
                                    width=400, height=50
                                ),
                                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                    fill="rgba(0,0,0,0.3)"
                                ),
                            ),
                            opts.GraphicText(
                                graphic_item=opts.GraphicItem(
                                    left="center", top="center", z=100
                                ),
                                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                                    text="某商店{}年营业额".format(i),
                                    font="bold 26px Microsoft YaHei",
                                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                        fill="#fff"
                                    ),
                                ),
                            ),
                        ],
                    )
                ],
            )
        )
        tl.add(bar, "{}年".format(i)) 
        return tl  
Exemple #5
0
def bar_graphic_rect_text_two_component() -> Bar:
    c = (
        Bar()
        .add_xaxis(Faker.choose())
        .add_yaxis("商家A", Faker.values())
        .add_yaxis("商家B", Faker.values())
        .set_global_opts(
            title_opts=opts.TitleOpts(title="Bar-Graphic Rect+Text 2 组件示例"),
            graphic_opts=[
                opts.GraphicGroup(
                    graphic_item=opts.GraphicItem(left="50%", top="15%"),
                    children=[
                        opts.GraphicRect(
                            graphic_item=opts.GraphicItem(
                                z=100, left="center", top="middle"
                            ),
                            graphic_shape_opts=opts.GraphicShapeOpts(
                                width=190, height=90
                            ),
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="#fff",
                                stroke="#555",
                                line_width=2,
                                shadow_blur=8,
                                shadow_offset_x=3,
                                shadow_offset_y=3,
                                shadow_color="rgba(0,0,0,0.3)",
                            ),
                        ),
                        opts.GraphicText(
                            graphic_item=opts.GraphicItem(
                                left="center", top="middle", z=100
                            ),
                            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                                text=JsCode(
                                    "['横轴表示数据类别',"
                                    "'纵轴表示数值的值',"
                                    "'这个文本块可以放在图中各',"
                                    "'种位置'].join('\\n')"
                                ),
                                font="14px Microsoft YaHei",
                                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                    fill="#333"
                                ),
                            ),
                        ),
                    ],
                )
            ],
        )
    )
    return c
def plot_timeline(df, data1 = 'Nuevos casos', data2 = 'Hospitalizados'):
    """[summary]

    Parameters
    ----------
    df : [type]
        [description]
    data1 : str, optional
        [description], by default 'Nuevos casos'
    data2 : str, optional
        [description], by default 'Hospitalizados'
    """
    tl = Timeline()
    calendar_dict = {
    1:'Ene',
    2:'Feb',
    3:'Mar',
    4:'Abr',
    5:'May',
    6:'Jun',
    7:'Jul',
    8:'Ag',
    9:'Sep',
    10:'Oct',
    11:'Nov',
    12:'Dic'
}
    for i in range(3, df.Mes.max()+1):
        bar = (
            Bar()
            .add_xaxis(pd.unique(df.Territorio).tolist())
            .add_yaxis(data1, df[df.Mes == i][data1].tolist())
            .add_yaxis(data2, df[df.Mes == i][data2].tolist())
            .set_global_opts(
                title_opts=opts.TitleOpts("Covid19 mes a mes"),
                graphic_opts=[
                    opts.GraphicGroup(
                        graphic_item=opts.GraphicItem(
                            rotation=JsCode("Math.PI / 4"),
                            bounding="raw",
                            right=100,
                            bottom=110,
                            z=100,
                        ),
                    )
                ],
            )
        )
        tl.add(bar,calendar_dict[i])
    st_pyecharts(tl)
Exemple #7
0
def bar_graphic_rect_text_one_component() -> Bar:
    c = (
        Bar()
        .add_xaxis(Faker.choose())
        .add_yaxis("商家A", Faker.values())
        .add_yaxis("商家B", Faker.values())
        .set_global_opts(
            title_opts=opts.TitleOpts(title="Bar-Graphic Rect+Text 1 组件示例"),
            graphic_opts=[
                opts.GraphicGroup(
                    graphic_item=opts.GraphicItem(
                        rotation=JsCode("Math.PI / 4"),
                        bounding="raw",
                        right=110,
                        bottom=110,
                        z=100,
                    ),
                    children=[
                        opts.GraphicRect(
                            graphic_item=opts.GraphicItem(
                                left="center", top="center", z=100
                            ),
                            graphic_shape_opts=opts.GraphicShapeOpts(
                                width=400, height=50
                            ),
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="rgba(0,0,0,0.3)"
                            ),
                        ),
                        opts.GraphicText(
                            graphic_item=opts.GraphicItem(
                                left="center", top="center", z=100
                            ),
                            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                                text="pyecharts bar chart",
                                font="bold 26px Microsoft YaHei",
                                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                    fill="#fff"
                                ),
                            ),
                        ),
                    ],
                )
            ],
        )
    )
    return c
Exemple #8
0
def syz_mark():
    """私人标记"""
    graphic_opts = [
        opts.GraphicGroup(
            graphic_item=opts.GraphicItem(
                rotation=JsCode("Math.PI / 4"),
                bounding="raw",
                right=80,
                bottom=80,
                z=100,
            ),
            children=[
                opts.GraphicRect(
                    graphic_item=opts.GraphicItem(
                        left="center", top="center", z=100
                    ),
                    graphic_shape_opts=opts.GraphicShapeOpts(
                        width=400, height=50
                    ),
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill="rgba(0,0,0,0.3)"
                    ),
                ),
                opts.GraphicText(
                    graphic_item=opts.GraphicItem(
                        left="center", top="center", z=100
                    ),
                    graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                        text="云博",
                        font="bold 26px Microsoft YaHei",
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            fill="#fff"
                        ),
                    ),
                ),
            ],
        )
    ]
    return graphic_opts
Exemple #9
0
    graphic_opts=opts.GraphicGroup(

        # 图形配置
        graphic_item=opts.GraphicItem(
            # 控制整体的位置
            left='75%',
            top='45%',
        ),
        children=[
            # GraphicRect控制方框的显示
            # opts.GraphicRect(
            #     graphic_item=opts.GraphicItem(
            #         z=100,  # 文本的高度
            #         left='center',
            #         top='middle',
            #     ),
            #     graphic_shape_opts=opts.GraphicShapeOpts(
            #         width=420,  # 宽度
            #         height=180,  # 高度
            #     ),
            #     graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
            #         fill='#fff',  # 文本框填充颜色
            #         stroke='#555',  # 笔画颜色
            #         line_width=2,
            #         shadow_blur=8,
            #         shadow_offset_x=3,
            #         shadow_offset_y=3,
            #         shadow_color='rgba(0,0,0,0.3)',  # 阴影颜色
            #     )
            # ),
            # 配置文本
            opts.GraphicText(
                # 配置文本的位置
                graphic_item=opts.GraphicItem(
                    left='center',
                    top='middle',
                    z=100,
                    scale=[1.5, 1.5]  # 缩放
                ),
                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                    text=
                    "直到{},\n全国的新冠状肺炎病毒的相关信息为:\n死亡病例为{}例,\n治愈病例为{}例,\n确诊病例为{}例,\n疑似病例为{}例,专家呼吁:\n广大积极配置国家政策进行疫情防疫工作"
                    .format(his.loc[0, '时间'], his.loc[0, '死亡数'],
                            his.loc[0, '治愈数'], his.loc[0, '确诊数'],
                            his.loc[0, '疑似数']),
                    font="15px Microsoft YaHei",
                    text_align='left',
                    text_vertical_align='middle',  # 垂直对齐方式 默认None
                    # 图形配置
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill='#ffdf22',
                        line_width=1.2,
                    )))
        ]))
Exemple #10
0
 )
 .set_global_opts(
     # 视觉映射配置,分段型
     visualmap_opts=opts.VisualMapOpts(is_show=True, is_piecewise=True, pieces=[{"value": 1, "color": '#F95DBA', "label": '1个运营商支持', "symbol": 'circle', "symbolSize": 6}, {"value": 2, "color": '#A64DFF', "label": '2个运营商支持', "symbol": 'circle', "symbolSize": 6}, {"value": 3, "color": '#4E70F0', "label": '3个运营商支持', "symbol": 'circle', "symbolSize": 6}], pos_left='22%', pos_bottom='7%'),
     # 图表标题及副标题
     title_opts=opts.TitleOpts(title="目前提供5G商用网络的城市", subtitle='数据来源:电信、移动、联通官方发布', pos_left='center', pos_top='-1%', item_gap=5),
     # 隐藏图例
     legend_opts=opts.LegendOpts(is_show=False),
     # 添加多个文本
     graphic_opts=[
         opts.GraphicGroup(
             graphic_item=opts.GraphicItem(left='68%', top='52%', z=99),
             children=[
                 opts.GraphicText(
                     graphic_item=opts.GraphicItem(left='68%', top='52%', z=100),
                     graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                         text='江浙沪共10\n个城市拥有\n商用5G网络',
                         font='bolder 14px Microsoft YaHei',
                         graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(fill="black"))
                 )
             ],
         ),
         opts.GraphicGroup(
             graphic_item=opts.GraphicItem(left='68%', top='61%', z=99),
             children=[
                 opts.GraphicText(
                     graphic_item=opts.GraphicItem(left='68%', top='61%', z=100),
                     graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                         text='上海 杭州 南京\n苏州 无锡 南通 常州\n宁波 温州 嘉兴 绍兴',
                         font='lighter 12px Microsoft YaHei',
                         graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(fill="black"))
                 )
Exemple #11
0
def get_year_chart(data, all_data, year):
    map_data = [[[x["name"], x["value"]] for x in d["data"]] for d in data
                if d["time"] == year][0]
    map_temp_data = [[[x["name"], x["value"][0]] for x in d["data"]]
                     for d in all_data if d["time"] == year][0]

    min_data, max_data = (
        min([d[1][0] for d in map_data]),
        max([d[1][0] for d in map_data]),
    )

    #map = Map(init_opts=opts.InitOpts(width="1900px", height="900px", bg_color="#ADD8E6",page_title="4.15全球疫情确诊人数", theme="white"))

    map_chart = (
        Map().add(
            maptype="world",  #默认地图为中国地图,加上这个参数改成世界地图
            series_name="",
            data_pair=map_temp_data,
            label_opts=opts.LabelOpts(is_show=False),
            is_map_symbol_show=False,
            itemstyle_opts={
                "normal": {
                    "areaColor": "#323c48",
                    "borderColor": "#404a59"
                },
                "emphasis": {
                    "label": {
                        "show": Timeline
                    },
                    "areaColor": "rgba(255,255,255, 0.5)",
                },
            },
        ).set_global_opts(
            title_opts=opts.TitleOpts(
                title="世界各国现存确诊人数变化",
                subtitle="确诊人数单位:例",
                pos_left="center",
                pos_top="top",
                title_textstyle_opts=opts.TextStyleOpts(
                    font_size=25, color="rgba(255,255,255, 0.9)"),
            ),
            tooltip_opts=opts.TooltipOpts(
                is_show=True,
                formatter=JsCode("""function(params) {
                    if ('value' in params.data) {
                        return params.data.value[2] + ': ' + params.data.value[0];
                    }
                }"""),
            ),
            visualmap_opts=opts.VisualMapOpts(
                is_calculable=True,
                dimension=0,
                pos_left="10",
                pos_top="center",
                range_text=["High", "Low"],
                range_color=["lightskyblue", "yellow", "orangered"],
                textstyle_opts=opts.TextStyleOpts(color="#ddd"),
                min_=min_data,
                max_=max_data,
            ),
        ))

    bar_x_data = [x[0] for x in map_data]

    # 这里注释的部分会导致 label 和 value 与 饼图不一致
    # 使用下面的 List[Dict] 就可以解决这个问题了。
    # bar_y_data = [x[1][0] for x in map_data]
    bar_y_data = [{"name": x[0], "value": x[1][0]} for x in map_data]
    bar = (Bar().add_xaxis(xaxis_data=bar_x_data).add_yaxis(
        series_name="",
        yaxis_index=1,
        y_axis=bar_y_data,
        label_opts=opts.LabelOpts(is_show=True,
                                  position="right",
                                  formatter="{b}: {c}"),
    ).reversal_axis().set_global_opts(
        xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)),
        yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)),
        tooltip_opts=opts.TooltipOpts(is_show=False),
        visualmap_opts=opts.VisualMapOpts(
            is_calculable=True,
            dimension=0,
            pos_left="10",
            pos_top="center",
            range_text=["High", "Low"],
            range_color=["lightskyblue", "yellow", "orangered"],
            textstyle_opts=opts.TextStyleOpts(color="#ddd"),
            min_=min_data,
            max_=max_data,
        ),
        graphic_opts=[
            opts.GraphicGroup(
                graphic_item=opts.GraphicItem(
                    rotation=JsCode("Math.PI / 4"),
                    bounding="raw",
                    right=110,
                    bottom=110,
                    z=100,
                ),
                children=[
                    opts.GraphicRect(
                        graphic_item=opts.GraphicItem(left="center",
                                                      top="center",
                                                      z=100),
                        graphic_shape_opts=opts.GraphicShapeOpts(width=400,
                                                                 height=50),
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            fill="rgba(0,0,0,0.3)"),
                    ),
                    opts.GraphicText(
                        graphic_item=opts.GraphicItem(left="center",
                                                      top="center",
                                                      z=100),
                        graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                            text=f"{str(year)}",
                            font="bold 26px Microsoft YaHei",
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="#fff"),
                        ),
                    ),
                ],
            )
        ],
    ))

    pie_data = [[x[0], x[1][0]] for x in map_data]
    percent_sum = sum([x[1][1] for x in map_data])
    rest_value = 0
    for d in map_data:
        rest_percent = 100.0
        rest_percent = rest_percent - percent_sum
        if d[1][1] != 0:
            rest_value = d[1][0] * (rest_percent / d[1][1])
            break
    pie_data.append(["其他国家", rest_value])
    pie = (Pie().add(
        series_name="",
        data_pair=pie_data,
        radius=["12%", "20%"],
        center=["75%", "85%"],
        itemstyle_opts=opts.ItemStyleOpts(border_width=1,
                                          border_color="rgba(0,0,0,0.3)"),
    ).set_global_opts(
        tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{b} {d}%"),
        legend_opts=opts.LegendOpts(is_show=False),
    ))

    grid_chart = (Grid().add(
        bar,
        grid_opts=opts.GridOpts(pos_left="10",
                                pos_right="45%",
                                pos_top="70%",
                                pos_bottom="5"),
    ).add(pie, grid_opts=opts.GridOpts()).add(map_chart,
                                              grid_opts=opts.GridOpts()))

    return grid_chart
Exemple #12
0
def get_year_chart(date):
    data = pd.read_csv('./china/{}.csv'.format(date))
    df_clear = data.drop(data[(data['地区'] == '香港')].index)
    df_clear1 = df_clear.drop(df_clear[df_clear['新增确诊'] == 0].index)
    df_clear2 = df_clear.drop(df_clear[df_clear['现有确诊'] == 0].index)
    name = list(df_clear['地区'])
    nowConfirm = list(df_clear1['新增确诊'])
    confirm = list(df_clear2['现有确诊'])
    heal = list(df_clear['治愈'])
    dead = list(df_clear['死亡'])
    map_chart = (Map().add(
        series_name="",
        data_pair=[list(z) for z in zip(name, confirm)],
        label_opts=opts.LabelOpts(is_show=False),
        is_map_symbol_show=False,
    ).set_global_opts(
        title_opts=opts.TitleOpts(
            title="现有疫情和新增疫情",
            subtitle="中国",
            pos_left="center",
            pos_top="top",
            title_textstyle_opts=opts.TextStyleOpts(
                font_size=25, color="rgba(255,255,255, 0.9)"),
        ),
        tooltip_opts=opts.TooltipOpts(is_show=True, ),
        visualmap_opts=opts.VisualMapOpts(
            is_calculable=True,
            dimension=0,
            pos_left="10",
            pos_top="center",
            range_text=["高风险地区", "低风险地区"],
            range_color=["lightskyblue", "yellow", "orangered"],
            textstyle_opts=opts.TextStyleOpts(color="#ddd"),
            min_=0,
            max_=100,
        ),
    ))

    bar = (Bar().add_xaxis(xaxis_data=name).add_yaxis(
        series_name="",
        yaxis_index=1,
        y_axis=confirm,
        label_opts=opts.LabelOpts(is_show=True,
                                  position="right",
                                  formatter="{b}: {c}"),
    ).reversal_axis().set_global_opts(
        xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)),
        yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)),
        tooltip_opts=opts.TooltipOpts(is_show=False),
        visualmap_opts=opts.VisualMapOpts(
            is_calculable=True,
            dimension=0,
            pos_left="10",
            pos_top="center",
            range_text=["高风险地区", "低风险地区"],
            range_color=["lightskyblue", "yellow", "orangered"],
            textstyle_opts=opts.TextStyleOpts(color="#ddd"),
            min_=0,
            max_=100,
        ),
        graphic_opts=[
            opts.GraphicGroup(
                graphic_item=opts.GraphicItem(
                    bounding="raw",
                    right=110,
                    bottom=11,
                    z=100,
                ),
                children=[
                    opts.GraphicRect(
                        graphic_item=opts.GraphicItem(left="center",
                                                      top="center",
                                                      z=100),
                        graphic_shape_opts=opts.GraphicShapeOpts(width=400,
                                                                 height=50),
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            fill="rgba(0,0,0,0.3)"),
                    ),
                    opts.GraphicText(
                        graphic_item=opts.GraphicItem(left="center",
                                                      top="center",
                                                      z=100),
                        graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                            text=date,
                            font="bold 26px Microsoft YaHei",
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="#fff"),
                        ),
                    ),
                ],
            )
        ],
    ))

    pie = (Pie().add(
        series_name="",
        data_pair=[list(z) for z in zip(name, nowConfirm)],
        radius=["12%", "20%"],
        center=["75%", "85%"],
        itemstyle_opts=opts.ItemStyleOpts(border_width=1,
                                          border_color="rgba(0,0,0,0.3)"),
    ).set_global_opts(
        tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{b} {d}%"),
        legend_opts=opts.LegendOpts(is_show=False),
    ))

    grid_chart = (Grid().add(
        bar,
        grid_opts=opts.GridOpts(pos_left="10",
                                pos_right="45%",
                                pos_top="70%",
                                pos_bottom="5"),
    ).add(pie, grid_opts=opts.GridOpts()).add(map_chart,
                                              grid_opts=opts.GridOpts()))

    return grid_chart
 opts.GraphicGroup(
     graphic_item=opts.GraphicItem(
         rotation=JsCode("Math.PI / 4"),
         bounding="raw",
         right=100,
         bottom=110,
         z=100,
     ),
     children=[
         opts.GraphicRect(
             graphic_item=opts.GraphicItem(left="center",
                                           top="center",
                                           z=100),
             graphic_shape_opts=opts.GraphicShapeOpts(
                 width=400, height=50),
             graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                 fill="rgba(0,0,0,0.3)"),
         ),
         opts.GraphicText(
             graphic_item=opts.GraphicItem(left="center",
                                           top="center",
                                           z=100),
             graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                 text="某商店{}年营业额".format(i),
                 font="bold 26px Microsoft YaHei",
                 graphic_basicstyle_opts=opts.
                 GraphicBasicStyleOpts(fill="#fff"),
             ),
         ),
     ],
 )
Exemple #14
0
def grid_horizontal1() -> Grid:
    bar1 = (
        Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
            .add_xaxis(['南亚', '撒哈拉以南非洲地区(不包括高收入)', '欧洲与中亚地区(不包括高收入)',
                        '拉丁美洲与加勒比海地区(不包括高收入)', '东亚与太平洋地区(不包括高收入)', '中东与北非地区(不包括高收入)'])
            .add_yaxis("Region",
                       [Region.count('南亚'),
                        Region.count('撒哈拉以南非洲地区(不包括高收入)'),
                        Region.count('欧洲与中亚地区(不包括高收入)'),
                        Region.count('拉丁美洲与加勒比海地区(不包括高收入)'),
                        Region.count('东亚与太平洋地区(不包括高收入)'),
                        Region.count('中东与北非地区(不包括高收入)')])
            .set_global_opts(title_opts=opts.TitleOpts(title="Region", subtitle="2019", pos_left="2%"),
                             legend_opts=opts.LegendOpts(pos_left="20%"))
    )
    bar = (
        Bar()

            .set_global_opts(
            title_opts=opts.TitleOpts(title=""),
            graphic_opts=[
                opts.GraphicGroup(
                    graphic_item=opts.GraphicItem(
                        # 控制整体的位置
                        left="52%",
                        top="7%",
                    ),
                    children=[

                        # opts.GraphicRect控制方框的显示
                        # 如果不需要方框,去掉该段即可
                        opts.GraphicRect(
                            graphic_item=opts.GraphicItem(
                                z=100,
                                left="center",
                                top="middle",
                            ),
                            graphic_shape_opts=opts.GraphicShapeOpts(
                                width=400, height=440,
                            ),
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="#fff",
                                stroke="#555",
                                line_width=2,
                                shadow_blur=8,
                                shadow_offset_x=3,
                                shadow_offset_y=3,
                                shadow_color="rgba(0,0,0,0.3)",
                            )
                        ),
                        # opts.GraphicText控制文字的显示
                        opts.GraphicText(
                            graphic_item=opts.GraphicItem(
                                left="center",
                                top="middle",
                                z=100,
                            ),
                            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                                # 可以通过jsCode添加js代码,也可以直接用字符串
                                text=JsCode(
                                    "['根据世界银行(World Bank)统计数据, ',"
                                    "'南亚有8个国家、',"
                                    "'撒哈拉以南非洲地区有48个国家、',"
                                    "'欧洲与中亚地区有58个国家、',"
                                    "'拉丁美洲与加勒比海地区有42个国家、',"
                                    "'东亚与太平洋地区有37个国家、',"
                                    "'中东与北非地区有21个国家。',"
                                    "'  ',"
                                    "'此图除去了世界高收入国家,',"
                                    "'南亚8个国家、撒哈拉以南非洲地区47个国家、',"
                                    "'欧洲与中亚地区有21个国家、',"
                                    "'拉丁美洲与加勒比海地区有25个国家、',"
                                    "'东亚与太平洋地区有24个国家、',"
                                    "'中东与北非地区有13个国家不属于高收入国家。',"
                                    "'  ',"
                                    "'各地区高收入国家占比分别为(四舍五入取整):',"
                                    "'南亚0%、撒哈拉以南非洲地区98%、',"
                                    "'欧洲与中亚地区36%、',"
                                    "'拉丁美洲与加勒比海地区60%、',"
                                    "'东亚与太平洋地区65%、',"
                                    "'中东与北非地区62%',"
                                    "'  ',"
                                    "'收入与生活水平有一定联系。',"
                                    "'就各地区高收入国家占比,',"
                                    "'可对各地区生活水平做出以下排序(高到低):',"
                                    "'撒哈拉以南非洲地区>东亚与太平洋地区>',"
                                    "'中东与北非地区>拉丁美洲与加勒比海地区>',"
                                    "'欧洲与中亚地区>南亚'].join('\\n')"
                                ),
                                font="14px Microsoft YaHei",
                                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                    fill="#333"
                                )
                            )
                        )
                    ]
                )
            ],
        )
    )

    grid1 = (
        Grid()
            .add(bar, grid_opts=opts.GridOpts(pos_left="55%"))
            .add(bar1, grid_opts=opts.GridOpts(pos_right="55%"))
    )
    return grid1
Exemple #15
0
 def line_render_qimai(self):
     c = Line(init_opts=opts.InitOpts(width="1200px", height="400px"))
     # c = Line()
     c.add_xaxis(self.x_value)
     c.add_yaxis(
         series_name=self.y_name,
         y_axis=self.y_value,
         is_symbol_show=self.is_symbol_show,  # 线上不用点标记
         color=self.color_list[0],
         linestyle_opts=opts.LineStyleOpts(width=self.line_width),  # 线条加粗
         label_opts=opts.LabelOpts(is_show=self.is_show))
     c.set_global_opts(
         title_opts=opts.TitleOpts(
             title=self.title,
             pos_top="2%",  # 距离顶层2%
             pos_left="center",
             title_textstyle_opts=opts.TextStyleOpts(
                 color="#666",
                 font_size=16,
                 font_weight='normal',
                 font_family='Microsoft YaHei'),
         ),
         tooltip_opts=opts.TooltipOpts(trigger="axis"),
         # legend_opts=opts.LegendOpts(pos_left="center", pos_top=self.pos_top, legend_icon='circle'),
         legend_opts=opts.LegendOpts(pos_left="center",
                                     pos_top='bottom',
                                     legend_icon='circle'),
         yaxis_opts=opts.AxisOpts(
             type_="value",
             max_=self.y_max,
             min_=self.y_min,
             is_inverse=self.y_is_inverse,  # 反向Y轴;
             boundary_gap=self.boundary_gap,  # 封闭坐标轴,左右都有顶上的刻度线;
             axislabel_opts=opts.LabelOpts(color="#7D7D7D"),
             axisline_opts=opts.AxisLineOpts(
                 linestyle_opts=opts.LineStyleOpts(width=1.5,
                                                   color="#A0A7B3")),
             axistick_opts=opts.AxisTickOpts(is_show=True, is_inside=True),
             splitline_opts=opts.SplitLineOpts(
                 is_show=True,
                 linestyle_opts=opts.LineStyleOpts(
                     color="#E2E2E2")),  # 设置网格线;
         ),
         xaxis_opts=opts.AxisOpts(
             type_="category",
             min_=self.x_min,
             boundary_gap=self.boundary_gap,
             is_inverse=self.x_is_inverse,  # 反向X轴;
             axislabel_opts=opts.LabelOpts(color="#7D7D7D"),
             axisline_opts=opts.AxisLineOpts(
                 linestyle_opts=opts.LineStyleOpts(width=1.5,
                                                   color="#A0A7B3")),
             axistick_opts=opts.AxisTickOpts(is_show=True, is_inside=True),
             splitline_opts=opts.SplitLineOpts(
                 is_show=True,
                 linestyle_opts=opts.LineStyleOpts(color="#E2E2E2")),
         ),
         graphic_opts=[
             opts.GraphicGroup(
                 graphic_item=opts.GraphicItem(
                     rotation=JsCode("Math.PI / 500"),
                     bounding="raw",
                     right=700,
                     bottom=150,
                     z=100,
                 ),
                 children=[
                     opts.GraphicRect(
                         graphic_item=opts.GraphicItem(left="center",
                                                       top="center",
                                                       z=100),
                         graphic_shape_opts=opts.GraphicShapeOpts(
                             width=400, height=50),
                         graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                             fill="rgba(0,0,0,0)"),
                     ),
                     opts.GraphicText(
                         graphic_item=opts.GraphicItem(left="center",
                                                       top="center",
                                                       z=100),
                         graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                             text="七麦数据",
                             # font="bold 26px Microsoft YaHei",
                             font="26px Microsoft YaHei",
                             graphic_basicstyle_opts=opts.
                             GraphicBasicStyleOpts(fill="#D5D5D5"),
                         ),
                     ),
                 ],
             )
         ],
         # 下方为图片水印代码;
         #             graphic_opts=[
         #                 opts.GraphicImage(
         #                     graphic_item=opts.GraphicItem(
         #                         id_="logo",
         #                         left='142',
         #                         z='10',
         #                         # 距离上边界距离
         #                         top='340',
         #                         # 负数则显示在图表下层
         #                         z_level=-1
         #                     ),
         #                     graphic_imagestyle_opts=opts.GraphicImageStyleOpts(
         #                         # 指定图片地址,最好选用png
         #                         image="https://tva1.sinaimg.cn/large/008eGmZEly1gmfcjqkwrkj302q00mq2q.jpg",
         #                         # 长设置
         #                         width=100,
         #                         height=23,
         #                         opacity=1,
         #                     ),
         #                 ),
         #             ]
     )
     # 插入其他y线条;
     if len(self.args) > 0:
         for num in range(len(self.args[0])):
             if num + 1 > len(self.color_list) - 1:
                 color_str = ''
             else:
                 color_str = self.color_list[num + 1]
             c.add_yaxis(
                 series_name=self.args[0][num],
                 y_axis=self.args[1][num],
                 is_symbol_show=self.is_symbol_show,  # 线上不用点标记
                 color=color_str,
                 linestyle_opts=opts.LineStyleOpts(
                     width=self.line_width),  # 线条加粗
                 label_opts=opts.LabelOpts(is_show=self.is_show),
             )
     self.c_render = c
     return c
 opts.GraphicGroup(
     # 图形的配置项
     #原生图形配置项
     graphic_item=opts.GraphicItem(
         #旋转(rotation):默认值是 0。表示旋转的弧度值。正值表示逆时针旋转
         rotation=JsCode("Math.PI / 4"),
         # 决定此图形元素在定位时,对自身的包围盒计算方式
         bounding="raw",
         #描述怎么根据父元素进行定位。
         right=110,
         bottom=110,
         z=100,
     ),
     children=[
         #原生图形矩形配置项
         opts.GraphicRect(
             #graphic_item:图形的配置项
             #GraphicItem:原生图形配置项
             graphic_item=opts.GraphicItem(
                 #left:描述怎么根据父元素进行定位。    top :配置和 left 及 right 相同    z 方向的高度,决定层叠关系。
                 left="center",
                 top="center",
                 z=100),
             # 图形的形状配置项,
             #原生图形形状配置项   width: 图形元素的宽度。    height: 图形元素的高度。
             graphic_shape_opts=opts.GraphicShapeOpts(width=400,
                                                      height=50),
             # 图形基本配置项
             #原生图形基础配置项
             graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                 # 填充色
                 fill="rgba(0,0,0,0.3)"),
         ),
         #原生图形文本配置项
         opts.GraphicText(
             #GraphicItem:原生图形配置项
             #left:描述怎么根据父元素进行定位。   top :配置和 left 及 right 相同    z 方向的高度,决定层叠关系。
             graphic_item=opts.GraphicItem(left="center",
                                           top="center",
                                           z=100),
             #图形文本样式的配置项
             #原生图形文本样式配置项
             graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                 #text:文本块文字。可以使用 \n 来换行
                 text="pyecharts bar chart",
                 # font:字体大小、字体类型、粗细、字体样式。
                 font="bold 26px Microsoft YaHei",
                 # 图形基本配置项
                 # 原生图形基础配置项
                 graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                     # 填充色
                     fill="#fff"),
             ),
         ),
     ],
 )
Exemple #17
0
 opts.GraphicGroup(
     graphic_item=opts.GraphicItem(left="50%", top="15%"),
     children=[
         opts.GraphicRect(
             graphic_item=opts.GraphicItem(z=100,
                                           left="center",
                                           top="middle"),
             graphic_shape_opts=opts.GraphicShapeOpts(width=190,
                                                      height=90),
             graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                 fill="#fff",
                 stroke="#555",
                 line_width=2,
                 shadow_blur=8,
                 shadow_offset_x=3,
                 shadow_offset_y=3,
                 shadow_color="rgba(0,0,0,0.3)",
             ),
         ),
         opts.GraphicText(
             graphic_item=opts.GraphicItem(left="center",
                                           top="middle",
                                           z=100),
             graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                 text=JsCode("['横轴表示数据类别',"
                             "'纵轴表示数值的值',"
                             "'这个文本块可以放在图中各',"
                             "'种位置'].join('\\n')"),
                 font="14px Microsoft YaHei",
                 graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                     fill="#333"),
             ),
         ),
     ],
 )
 def draw_rose_piture(self,my_rose_data):
   total_position = 0
   for x in my_rose_data:
     total_position = total_position + x[1]
   #print(total_position)
   if os.path.isfile('pie_rosetype.html'):
      os.remove('.\pie_rosetype.html')
   c = (
       Pie()
       .add(
           "",
           my_rose_data,
           radius=["30%", "75%"],
           #center=["25%", "50%"],
           rosetype="radius",
           #label_opts=opts.LabelOpts(is_show=False),
       )
       #.add(
       #    "",
       #    my_rose_data,
       #    radius=["30%", "75%"],
       #    center=["75%", "50%"],
       #    rosetype="area",
       #)
       .set_global_opts(
           title_opts=opts.TitleOpts(title="Positions",pos_left="8%",pos_top="8%"),
           graphic_opts=[
               opts.GraphicGroup(
                   graphic_item=opts.GraphicItem(
                       # 控制整体的位置
                       right="15%",
                       bottom="5%",
                   ),
                   children=[
                       # opts.GraphicRect控制方框的显示
                       # 如果不需要方框,去掉该段即可
                       #opts.GraphicRect(
                       #    graphic_item=opts.GraphicItem(
                       #        z=100,
                       #        right="center",
                       #        bottom="middle",
                       #    ),
                       #    graphic_shape_opts=opts.GraphicShapeOpts(
                       #        width=120, height=70,
                       #    ),
                       #    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                       #        fill="#fff",
                       #        stroke="#555",
                       #        line_width=2,
                       #        shadow_blur=8,
                       #        shadow_offset_x=3,
                       #        shadow_offset_y=3,
                       #        shadow_color="rgba(144,238,144,0.3)",
                       #    )
                       #),
                       # opts.GraphicText控制文字的显示
                       opts.GraphicText(
                           graphic_item=opts.GraphicItem(
                               left="center",
                               top="middle",
                               z=100,
                           ),
                           graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                               # 可以通过jsCode添加js代码,也可以直接用字符串
                               text="Total:"+str(total_position)+"%",
                               font="bolder 21px Microsoft YaHei",
                               graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                   fill="#C537B6"
                               )
                           )
                       )
                   ]
               )
           ]
       )
       .set_series_opts(label_opts=opts.LabelOpts(formatter="{b} {c}%"))
       .render("pie_rosetype.html")
   )
Exemple #19
0
 graphic_opts=opts.GraphicGroup(
     # 控制文本相对于整体的位置
     graphic_item=opts.GraphicItem(
         #
         left='75%',
         top='5%'),
     # 设置文本
     children=[
         # # 设置文本框
         # opts.GraphicRect(
         #
         # ),
         # 设置文本
         opts.GraphicText(
             # 配置的文本相对于 --->文本框的位置
             graphic_item=opts.GraphicItem(
                 left='center',  # 文本相对于文本框的左位置
                 top='middle',  # 文本相对文本框的上位置
                 z=100,  # 字在文本框的z轴方向100的位置
                 scale=[2.5, 2.5],  # [横向缩放的倍数, 纵向缩放的倍数]
             ),
             # 设置文本内容
             graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                 # 文本内容
                 text="""截止2020-01-22日\n武汉封城前的迁徙路线""",
                 font='13px Microsoft YaHei',  # 字体
                 text_align='left',  # 水平对其方式: 左对齐
                 text_vertical_align='middle',  # 垂直对其方式:居中
                 # 图形化基本设置
                 graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                     fill='#ffdf22'  # 设置颜色
                 )))
     ]))
Exemple #20
0
def line_base() -> Line:
    bar = (
        Bar()

            .set_global_opts(
            title_opts=opts.TitleOpts(title=""),
            graphic_opts=[
                opts.GraphicGroup(
                    graphic_item=opts.GraphicItem(
                        # 控制整体的位置
                        left="5%",
                        top="10%",
                    ),
                    children=[

                        # opts.GraphicRect控制方框的显示
                        # 如果不需要方框,去掉该段即可
                        opts.GraphicRect(
                            graphic_item=opts.GraphicItem(
                                z=100,
                                left="center",
                                top="middle",
                            ),
                            graphic_shape_opts=opts.GraphicShapeOpts(
                                width=800, height=400,
                            ),
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="#fff",
                                stroke="#555",
                                line_width=2,
                                shadow_blur=8,
                                shadow_offset_x=3,
                                shadow_offset_y=3,
                                shadow_color="rgba(0,0,0,0.3)",
                            )
                        ),
                        # opts.GraphicText控制文字的显示
                        opts.GraphicText(
                            graphic_item=opts.GraphicItem(
                                left="center",
                                top="middle",
                                z=100,
                            ),
                            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                                # 可以通过jsCode添加js代码,也可以直接用字符串
                                text=JsCode(
                                    "['根据世界银行(World Bank)统计数据: ',"
                                    "'  ',"
                                    "'2007-2009年中,新加坡、马耳他、冰岛以及哥斯达黎加等国,位列世界高科技出口的前列,高科技出口数量远超其他国家。',"
                                    "'  ',"
                                    "'  ',"
                                    "'2010-2014年中,随着各国家的发展,越来越多的国家开始出口高科技,比如马来西亚,格陵兰岛,尼日尔、哈萨克斯坦等国家,',"
                                    "'  ',"
                                    "'开始增加自己的高科技出口,在世界高科技出口中开始崭露头角。',"
                                    "'  ',"
                                    "'  ',"
                                    "'2015-2018年中,高科技出口的前列国家变化很大,有塞舌尔,阿拉伯联合酋长国,百慕大群岛等国的昙花一现,',"
                                    "'  ',"
                                    "'也有帕劳共和国以及菲律宾等国经久不衰,世界高科技出口的国家朝着多极化方向发展。',"
                                    "'  ',"
                                    "'  ',"
                                    "'表明近十几年来,世界各国都认识到了高科技出口的重要性,',"
                                    "'  ',"
                                    "'  ',"
                                    "'开始利用先进的技术基础设施、商业政策环境以及获得商业融资渠道的便利性等因素,',"
                                    "'  ',"
                                    "'出口本国的高科技产品,以增加国家在世界上的竞争力。'].join('\\n')"
                                ),
                                font="14px Microsoft YaHei",
                                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                    fill="#333"
                                )
                            )
                        )
                    ]
                )
            ],
        )
    )
    return bar
Exemple #21
0
def grid_horizontal() -> Grid:
    bar0 = (
        Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
            .add_xaxis(['高收入国家', '低收入国家', '中低等收入国家', '中高等收入国家'])
            .add_yaxis("Income_Group", [high, low, middle_low, middle_high])
            .set_global_opts(title_opts=opts.TitleOpts(title="Income_Group", subtitle="2019", pos_left="2%"),
                             legend_opts=opts.LegendOpts(pos_left="20%"))
    )
    bar = (
        Bar()

            .set_global_opts(
            title_opts=opts.TitleOpts(title=""),
            graphic_opts=[
                opts.GraphicGroup(
                    graphic_item=opts.GraphicItem(
                        # 控制整体的位置
                        left="52%",
                        top="7%",
                    ),
                    children=[

                        # opts.GraphicRect控制方框的显示
                        # 如果不需要方框,去掉该段即可
                        opts.GraphicRect(
                            graphic_item=opts.GraphicItem(
                                z=100,
                                left="center",
                                top="middle",
                            ),
                            graphic_shape_opts=opts.GraphicShapeOpts(
                                width=415, height=440,
                            ),
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="#fff",
                                stroke="#555",
                                line_width=2,
                                shadow_blur=8,
                                shadow_offset_x=3,
                                shadow_offset_y=3,
                                shadow_color="rgba(0,0,0,0.3)",
                            )
                        ),
                        # opts.GraphicText控制文字的显示
                        opts.GraphicText(
                            graphic_item=opts.GraphicItem(
                                left="center",
                                top="middle",
                                z=100,
                            ),
                            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                                # 可以通过jsCode添加js代码,也可以直接用字符串
                                text=JsCode(
                                    "['世界银行是按人均国民总收入对世界各国经济发展水平进行分组。 ',"
                                    "'通常把世界各国分成四组,',"
                                    "'即低收入国家、中等偏下收入国家、',"
                                    "'中等偏上收入国家和高收入国家。',"
                                    "'但以上标准不是固定不变的,而是随着经济的发展不断进行调整。',"
                                    "'中等偏下收入国家和中等偏上收入国家合称为中等收入国家。',"
                                    "'  ',"
                                    "'按世界银行(World Bank)公布的数据,',"
                                    "'2018年的最新收入分组标准为:',"
                                    "'人均国民总收入低于995美元为低收入国家,',"
                                    "'在996至3895美元之间为中等偏下收入国家,',"
                                    "'在3896至12055元之间为中等偏上收入国家,',"
                                    "'高于12055美元为高收入国家。',"
                                    "'  ',"
                                    "'此图所统计的217个经济体中,',"
                                    "'高收入国家79个,低收入国家31个,',"
                                    "'中低等收入国家47个,中高等收入国家60个。',"
                                    "'由此看出,',"
                                    "'全球大多数国家收入水平都处于中等收入水平或者高收入水平,',"
                                    "'只有少部分国家处于低收入水平。',"
                                    "'  ',"
                                    "'美国、日本、英法德以及韩国等为高收入国家;',"
                                    "'俄罗斯、巴西、中国、土耳其、马来西亚等',"
                                    "'目前是中高等收入国家;',"
                                    "'印度、巴基斯坦、越南、菲律宾等国为中低收入国家;',"
                                    "'阿富汗、坦桑尼亚、柬埔寨、尼泊尔、埃塞俄比亚等',"
                                    "'为低收入国家。'].join('\\n')"
                                ),
                                font="14px Microsoft YaHei",
                                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                    fill="#333"
                                )
                            )
                        )
                    ]
                )
            ],
        )
    )

    grid = (
        Grid()
            .add(bar, grid_opts=opts.GridOpts(pos_left="55%"))
            .add(bar0, grid_opts=opts.GridOpts(pos_right="55%"))
    )
    return grid
Exemple #22
0
def bar_base() -> Line:
    bar = (
        Bar()

            .set_global_opts(
            title_opts=opts.TitleOpts(title=""),
            graphic_opts=[
                opts.GraphicGroup(
                    graphic_item=opts.GraphicItem(
                        # 控制整体的位置
                        left="5%",
                        top="10%",
                    ),
                    children=[

                        # opts.GraphicRect控制方框的显示
                        # 如果不需要方框,去掉该段即可
                        opts.GraphicRect(
                            graphic_item=opts.GraphicItem(
                                z=100,
                                left="center",
                                top="middle",
                            ),
                            graphic_shape_opts=opts.GraphicShapeOpts(
                                width=800, height=400,
                            ),
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="#fff",
                                stroke="#555",
                                line_width=2,
                                shadow_blur=8,
                                shadow_offset_x=3,
                                shadow_offset_y=3,
                                shadow_color="rgba(0,0,0,0.3)",
                            )
                        ),
                        # opts.GraphicText控制文字的显示
                        opts.GraphicText(
                            graphic_item=opts.GraphicItem(
                                left="center",
                                top="middle",
                                z=100,
                            ),
                            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                                # 可以通过jsCode添加js代码,也可以直接用字符串
                                text=JsCode(
                                    "['根据世界银行(World Bank)统计数据, ',"
                                    "'  ',"
                                    "'亚洲地区在近十几年来,有着越来越多的国家增加高科技的出口,并且大体上呈现逐年增加的趋势。',"
                                    "'  ',"
                                    "'  ',"
                                    "'欧洲地区,随着大多数经济体的衰落或者停滞不前,',"
                                    "'  ',"
                                    "'欧洲各地的高科技出口都难以取得进展,但仍然处于世界高科技出口的中上行列。',"
                                    "'  ',"
                                    "'  ',"
                                    "'北美洲,得益于美国加拿大等强国,一直都保持的稳定的高科技出口。',"
                                    "'  ',"
                                    "'  ',"
                                    "'南美洲,在金融危机之后,开始出现了高科技出口,并且也是大体上呈现高科技出口国家逐年增加的趋势;',"
                                    "'  ',"
                                    "'  ',"
                                    "'非洲地区是目前世界上高科技出口水平较弱的地区,近十几年来无明显变化趋势,处于世界高科技出口的下游,水平有待加强。',"
                                    "'  ',"
                                    "'  ',"
                                    "'说明经济的不确定性对世界的发展状况息息相关,国际政治格局和贸易关系迅速变化导致全球市场高度不确定,',"
                                    "'  ',"
                                    "'在这样的十几年里,制度的质量似乎是促进繁荣的重要因素。',"
                                    "'  ',"
                                    "'强有力的制度框架为企业投资和创新提供了稳定性,确保了公民更高的生活质量。'].join('\\n')"
                                ),
                                font="14px Microsoft YaHei",
                                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                    fill="#333"
                                )
                            )
                        )
                    ]
                )
            ],
        )
    )
    return bar
Exemple #23
0
            left="center",
            top="center",
            z=100
        ),
        graphic_shape_opts=opts.GraphicShapeOpts(
            width=400,
            height=50
        ),
        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
            fill="rgba(0, 0, 0, 0.3)"
        )
    ),
    "printer" = opts.GraphicGroup(
        rotation=JsCode("Math.PI / 4"),
        bounding="raw",
        right=110,
        bottom=110,
        z=100
    ),
    "children"=[GRAPH["rect"], GRAPH["text"]]
}


# %% [markdown]
# ### Style Options
TEXT = {
    "white": opts.TextStyleOpts(
        color="#ffffff"
    )
}
LINE = {
Exemple #24
0
 opts.GraphicGroup(
     graphic_item=opts.GraphicItem(
         bounding="raw",
         right=150,
         bottom=50,
         z=100,
     ),
     children=[
         opts.GraphicRect(
             graphic_item=opts.GraphicItem(
                 left="center", top="center", z=100),
             graphic_shape_opts=opts.GraphicShapeOpts(width=200,
                                                      height=50),
             graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                 fill="rgba(0,0,0,0.3)"),
         ),
         opts.GraphicText(
             graphic_item=opts.GraphicItem(left="center",
                                           top="center",
                                           z=100),
             graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                 text=JsCode(
                     "['钻石号邮轮', '累计确诊人数:{}人'].join('\\n')".format(
                         dict(oversea_confirm)
                         ['Diamond Princess Cruise Ship'])),
                 font="bold 16px Microsoft YaHei",
                 graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                     fill="#fff"),
             ),
         ),
     ],
 )
Exemple #25
0
 graphic_opts=opts.GraphicGroup(
     # 控制文本相对于整体的位置
     graphic_item=opts.GraphicItem(
         #
         left='80%',
         top='45%'),
     # 设置文本
     children=[
         # # 设置文本框
         # opts.GraphicRect(
         #
         # ),
         # 设置文本
         opts.GraphicText(
             # 配置的文本相对于 --->文本框的位置
             graphic_item=opts.GraphicItem(
                 left='center',  # 文本相对于文本框的左位置
                 top='middle',  # 文本相对文本框的上位置
                 z=100,  # 字在文本框的z轴方向100的位置
                 scale=[1.3, 1.5],  # [横向缩放的倍数, 纵向缩放的倍数]
             ),
             # 设置文本内容
             graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                 # 文本内容
                 text=
                 """直到{},\n全国的新冠状病毒的相关信息为:\n死亡数例数为{}列\n治愈数例数为{}例\n疑似数例数为{}例\n确诊数例数为{}例"""
                 .format(history_data.loc[0, '时间'], history_data.loc[0,
                                                                     '死亡数'],
                         history_data.loc[0, '治愈数'],
                         history_data.loc[0,
                                          '疑似数'], history_data.loc[0,
                                                                   '确诊数']),
                 font='13px Microsoft YaHei',  # 字体
                 text_align='left',  # 水平对其方式: 左对齐
                 text_vertical_align='middle',  # 垂直对其方式:居中
                 # 图形化基本设置
                 graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                     fill='#ffdf22'  # 设置颜色
                 )))
     ]))
Exemple #26
0
 opts.GraphicGroup(
     graphic_item=opts.GraphicItem(right="0%", top="0%"),
     children=[
         opts.GraphicRect(
             graphic_item=opts.GraphicItem(z=500,
                                           left="center",
                                           top="middle"),
             graphic_shape_opts=opts.GraphicShapeOpts(
                 width=280, height=130),
             graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                 fill="rgba(0,0,0,0.3)",
                 #stroke="#555",
                 line_width=2,
                 shadow_blur=8,
                 shadow_offset_x=3,
                 shadow_offset_y=3,
                 shadow_color="rgba(0,0,0,0.3)",
             ),
         ),
         opts.GraphicText(
             graphic_item=opts.GraphicItem(left="center",
                                           top="middle",
                                           z=500),
             graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                 text="\n\n".join(top_titles[idx][:5]),
                 font="10px Microsoft YaHei",
                 graphic_basicstyle_opts=opts.
                 GraphicBasicStyleOpts(fill="#fff"),
             ),
         ),
     ],
 )
def bmap_custom() -> BMap:
    with open(
        os.path.join("fixtures", "bmap-custom-data.json"), "r", encoding="utf-8"
    ) as f:
        j = json.load(f)
    color_list = ["#070093", "#1c3fbf", "#1482e5", "#70b4eb", "#b4e0f3", "#ffffff"]
    c = (
        BMap()
        .add_schema(
            baidu_ak=BAIDU_MAP_AK,
            center=[116.46, 39.92],
            zoom=11.8,
            is_roam=True,
            map_style={
                "styleJson": [
                    {
                        "featureType": "water",
                        "elementType": "all",
                        "stylers": {"color": "#d1d1d1"},
                    },
                    {
                        "featureType": "land",
                        "elementType": "all",
                        "stylers": {"color": "#f3f3f3"},
                    },
                    {
                        "featureType": "railway",
                        "elementType": "all",
                        "stylers": {"visibility": "off"},
                    },
                    {
                        "featureType": "highway",
                        "elementType": "all",
                        "stylers": {"color": "#999999"},
                    },
                    {
                        "featureType": "highway",
                        "elementType": "labels",
                        "stylers": {"visibility": "off"},
                    },
                    {
                        "featureType": "arterial",
                        "elementType": "geometry",
                        "stylers": {"color": "#fefefe"},
                    },
                    {
                        "featureType": "arterial",
                        "elementType": "geometry.fill",
                        "stylers": {"color": "#fefefe"},
                    },
                    {
                        "featureType": "poi",
                        "elementType": "all",
                        "stylers": {"visibility": "off"},
                    },
                    {
                        "featureType": "green",
                        "elementType": "all",
                        "stylers": {"visibility": "off"},
                    },
                    {
                        "featureType": "subway",
                        "elementType": "all",
                        "stylers": {"visibility": "off"},
                    },
                    {
                        "featureType": "manmade",
                        "elementType": "all",
                        "stylers": {"color": "#d1d1d1"},
                    },
                    {
                        "featureType": "local",
                        "elementType": "all",
                        "stylers": {"color": "#d1d1d1"},
                    },
                    {
                        "featureType": "arterial",
                        "elementType": "labels",
                        "stylers": {"visibility": "off"},
                    },
                    {
                        "featureType": "boundary",
                        "elementType": "all",
                        "stylers": {"color": "#fefefe"},
                    },
                    {
                        "featureType": "building",
                        "elementType": "all",
                        "stylers": {"color": "#d1d1d1"},
                    },
                    {
                        "featureType": "label",
                        "elementType": "labels.text.fill",
                        "stylers": {"color": "rgba(0,0,0,0)"},
                    },
                ]
            },
        )
        .add_js_funcs(
            """
        var lngExtent = [39.5, 40.6];
        var latExtent = [115.9, 116.8];
        var cellCount = [50, 50];
        var cellSizeCoord = [
            (lngExtent[1] - lngExtent[0]) / cellCount[0],
            (latExtent[1] - latExtent[0]) / cellCount[1]
        ];
        var gapSize = 0;

        function renderItem(params, api) {
            var lngIndex = api.value(0);
            var latIndex = api.value(1);
            var pointLeftTop = getCoord(params, api, lngIndex, latIndex);
            var pointRightBottom = getCoord(params, api, lngIndex + 1, latIndex + 1);

            return {
                type: 'rect',
                shape: {
                    x: pointLeftTop[0],
                    y: pointLeftTop[1],
                    width: pointRightBottom[0] - pointLeftTop[0],
                    height: pointRightBottom[1] - pointLeftTop[1]
                },
                style: api.style({
                    stroke: 'rgba(0,0,0,0.1)'
                }),
                styleEmphasis: api.styleEmphasis()
            };
        }

        function getCoord(params, api, lngIndex, latIndex) {
            var coords = params.context.coords || (params.context.coords = []);
            var key = lngIndex + '-' + latIndex;
            return coords[key] || (coords[key] = api.coord([
                +(latExtent[0] + lngIndex * cellSizeCoord[0]).toFixed(6),
                +(lngExtent[0] + latIndex * cellSizeCoord[1]).toFixed(6)
            ]));
        }
        """
        )
        .add(
            series_name="",
            data_pair=j["data"],
            type_=ChartType.CUSTOM,
            render_item=JsCode("renderItem"),
            itemstyle_opts=opts.ItemStyleOpts(color="yellow"),
            encode={"tooltip": 2},
        )
        .set_global_opts(
            title_opts=opts.TitleOpts(title="BMap-Custom 图"),
            tooltip_opts=opts.TooltipOpts(is_show=True, formatter=None),
            visualmap_opts=opts.VisualMapOpts(
                is_piecewise=True,
                pos_top="10",
                pos_left="10",
                is_inverse=True,
                pieces=[
                    {"value": i, "color": color_list[i]} for i in range(len(color_list))
                ],
                dimension=2,
                border_color="#ccc",
                border_width=2,
                background_color="#eee",
                range_opacity=0.7,
            ),
            graphic_opts=[
                opts.GraphicGroup(
                    graphic_item=opts.GraphicItem(
                        rotation=JsCode("Math.PI / 4"),
                        bounding="raw",
                        right=110,
                        bottom=110,
                        z=100,
                    ),
                    children=[
                        opts.GraphicRect(
                            graphic_item=opts.GraphicItem(
                                left="center", top="center", z=100
                            ),
                            graphic_shape_opts=opts.GraphicShapeOpts(
                                width=400, height=50
                            ),
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="rgba(0,0,0,0.3)"
                            ),
                        ),
                        opts.GraphicText(
                            graphic_item=opts.GraphicItem(
                                left="center", top="center", z=100
                            ),
                            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                                text="Made by pyecharts",
                                font="bold 26px Microsoft YaHei",
                                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                    fill="#fff"
                                ),
                            ),
                        ),
                    ],
                )
            ],
        )
    )
    return c
    def generate_html(self):
        df = self.get_bond_data()
        data = self.get_XY_data(df)

        bigger = data['bigger']
        smaller = data['smaller']
        avg = data['avg']
        std = data['std']
        max_name = data['max_name']
        max_pct = data['max_pct']
        min_name = data['min_name']
        min_pct = data['min_pct']

        bar = (Bar().add_xaxis(list(data['result_dict'].keys())).add_yaxis(
            f"{self.today}-可转债价格分布", data['zz_list'],
            category_gap=3).add_yaxis(
                f"{self.today}-正股价格分布", data['zg_list'],
                category_gap=3).set_series_opts(
                    label_opts=opts.LabelOpts(is_show=True),
                    axispointer_opts=opts.AxisPointerOpts(is_show=True)).
               set_global_opts(
                   title_opts=opts.TitleOpts(title="可转债价格分布"),
                   xaxis_opts=opts.AxisOpts(
                       name="涨跌幅",
                       is_show=True,
                       name_rotate=30,
                   ),
                   graphic_opts=[
                       opts.GraphicGroup(
                           graphic_item=opts.GraphicItem(
                               left="70%",
                               top="20%",
                           ),
                           children=[
                               opts.GraphicText(
                                   graphic_item=opts.GraphicItem(
                                       left="center",
                                       top="middle",
                                       z=100,
                                   ),
                                   graphic_textstyle_opts=opts.
                                   GraphicTextStyleOpts(
                                       text=JsCode(
                                           f"['涨幅>=0:{bigger}',"
                                           f"'涨幅<0:{smaller}',"
                                           f"'平均涨幅:{avg}%',"
                                           f"'波动方差:{std}',"
                                           f"'',"
                                           f"'最大:{max_name}  {max_pct}%',"
                                           f"'最小:{min_name}  {min_pct}%',"
                                           "''].join('\\n')"),
                                       font="14px Microsoft YaHei",
                                       graphic_basicstyle_opts=opts.
                                       GraphicBasicStyleOpts(fill="#333")))
                           ])
                   ],
               ))

        bar.render(self.HMTL_PATH)
        # 自定义一个driver
        make_snapshot(snapshot, bar.render(), self.IMGAGE_PATH, driver=driver)