def draw_rank_change(axis_name_list, axis_data, data, to_file, svg_name):
    """
    平行坐标系
    :param axis_name_list:
    :param axis_data: 是str才行哦
    :param data: 格式 [[name, result],[name, result]] result 是 [[这里是值]] 的格式
    :param to_file:
    :param svg_name:
    :return:
    """
    # 设置schema
    parallel_axis = []
    for i in range(len(axis_name_list)):
        one_dict = {
            'dim': i,
            'name': axis_name_list[i],
            'type': 'category',
            'data': axis_data,
            'inverse': True,
            'nameTextStyle': opts.TextStyleOpts(font_size=15),
            'axisLabel': opts.LabelOpts(font_size=15)
        }
        parallel_axis.append(one_dict)
    # 设置结果
    p = Parallel(init_opts=opts.InitOpts(width="900px", height="600px", bg_color='White')) \
        .add_schema(schema=parallel_axis,
                    parallel_opts=opts.ParallelOpts(pos_top='5%',
                                                    pos_right='20%',
                                                    pos_left='10%',
                                                    )
                    )
    for i in range(len(data)):
        p = p.add(
            series_name=data[i][0],
            data=data[i][1],
            linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),
            is_smooth=True,
        )
    p = p.set_global_opts(
        legend_opts=opts.LegendOpts(
            type_="scroll",
            pos_left="85%",
            pos_top="18%",
            orient="vertical",
            backgroundColor='rgb(255, 255, 255)',
            item_width=25,
            item_height=15,
            textstyle_opts=opts.TextStyleOpts(font_size=15)),
        tooltip_opts=opts.TooltipOpts(position="right"),
        toolbox_opts=opts.ToolboxOpts(),
    )
    make_snapshot(snapshot, p.render(to_file), svg_name)  # 生成svg图片
Ejemplo n.º 2
0
    },
    {
        "dim": 3,
        "name": "Score",
        "type": "category",
        "data": ["Excellent", "Good", "OK", "Bad"],
    },
]

parallel_data = [[12.99, 100, 82, "Good"], [9.99, 80, 77, "OK"],
                 [20, 120, 60, "Excellent"]]
# init_opts=opts.InitOpts(width="800px",height="300px")
parallel = Parallel(init_opts=opts.InitOpts(width="800px", height="300px"))
parallel.add_schema(parallel_axis)
parallel.add(series_name="Related Indexes",
             data=parallel_data,
             linestyle_opts=opts.LineStyleOpts(width=4, opacity=0.5))

liquid = Liquid(init_opts=opts.InitOpts(width="300px", height="300px"))
liquid.add("liquid", [0.6, 0.7, 0.3])
liquid.set_global_opts(title_opts=opts.TitleOpts(title="Basic Example"))

heatmap_data = [[i, j, random.randint(0, 50)] for i in range(7)
                for j in range(7)]
heatmap = HeatMap()
heatmap.add_xaxis(Faker.week)
heatmap.add_yaxis(
    "相关表",
    Faker.week,
    heatmap_data,
    label_opts=opts.LabelOpts(is_show=True, position="inside"),
Ejemplo n.º 3
0
def find_value_render(query_filter, x_label, x, result, Data, query,
                      table_path, answer):

    colorList = ['#f36c6c', '#e6cf4e', '#20d180', '#0093ff']
    # x = ['GDP', 'Industry', 'Architecture', 'Service']
    # y = [990865, 317109, 70904, 534233]
    # x1 = ["周一"]
    # y1 = [11]

    Y = []
    # for i in range(len(y)):
    #     if i==0:
    #         Y.append(
    #             opts.BarItem(
    #                 name=x[i],
    #                 value=round(y[i], 2),
    #                 label_opts=opts.LabelOpts(position="insideTop"),
    #                 itemstyle_opts={
    #                     "normal": {
    #                         "color": colorList[0],
    #                         "barBorderRadius": [30, 30, 30, 30],
    #                     }
    #                 }
    #         ))
    #     else:
    #         Y.append(
    #             opts.BarItem(
    #                 name=x[i],
    #                 value=round(y[i], 2),
    #                 label_opts=opts.LabelOpts(position="insideTop"),
    #                 itemstyle_opts={
    #                     "normal": {
    #                         "color": "blue",
    #                         "barBorderRadius": [30, 30, 30, 30],
    #                     }
    #                 }
    #             ))
    bar1 = Bar()
    bar1.add_xaxis(x)
    bar1.add_yaxis(result[0][0],
                   y_axis=result[0][1],
                   label_opts=opts.LabelOpts(position="insideTop"))
    bar1.set_global_opts(
        yaxis_opts=opts.AxisOpts(is_show=False),
        xaxis_opts=opts.AxisOpts(
            axisline_opts=opts.AxisLineOpts(is_show=False),
            axispointer_opts=opts.AxisPointerOpts(is_show=False),
            axistick_opts=opts.AxisTickOpts(is_show=False)),
        title_opts=opts.TitleOpts(subtitle="When the search condition is " +
                                  query_filter,
                                  pos_left='center'),
        graphic_opts=[
            opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",
                    z=100,
                ),
                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                    # 可以通过jsCode添加js代码,也可以直接用字符串
                    text=[
                        '\n' + "Q:" + ' ' + query + '\n' + "\n" + 'A:' + ' ' +
                        answer
                    ],
                    font="14px Microsoft YaHei",
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill="#333")))
        ])
    bar2 = Bar()
    bar2.add_xaxis(x)
    for i in range(len(result)):
        bar2.add_yaxis(result[i][0], y_axis=result[i][1])
    bar2.set_global_opts(
        yaxis_opts=opts.AxisOpts(is_show=False),
        xaxis_opts=opts.AxisOpts(
            axisline_opts=opts.AxisLineOpts(is_show=False),
            axispointer_opts=opts.AxisPointerOpts(is_show=False),
            axistick_opts=opts.AxisTickOpts(is_show=False)),
        graphic_opts=[
            opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",
                    z=100,
                ),
                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                    # 可以通过jsCode添加js代码,也可以直接用字符串
                    text=[
                        '\n' + "\n" + "Q:" + ' ' + query + '\n' + "\n" + 'A:' +
                        ' ' + answer
                    ],
                    font="16px Microsoft YaHei",
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill="#333")))
        ])

    Label = []
    data = []
    for i in range(len(Data)):
        Label.append(str(Data[i][0]))
        data.append(Data[i][1])
    data = list(map(list, zip(*data)))
    parallel = Parallel()
    parallel_axis = []
    for i in range(len(Label)):
        parallel_axis.append({"dim": i, "name": Label[i]})
    parallel.add_schema(schema=parallel_axis)
    parallel.add("", data, is_smooth=True)
    parallel.set_global_opts(graphic_opts=[
        opts.GraphicText(
            graphic_item=opts.GraphicItem(
                left="center",
                top="bottom",
                z=100,
            ),
            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                # 可以通过jsCode添加js代码,也可以直接用字符串
                text=['\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' + answer],
                font="14px Microsoft YaHei",
                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                    fill="#333")))
    ])
    grid0 = Grid(init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer=globals.RenderType.SVG,
    ))
    grid0.add(bar1, grid_opts={'left': '20%', 'bottom': '34%'})
    option0 = grid0.dump_options_with_quotes()
    option0 = json.loads(option0)
    grid = Grid(init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer=globals.RenderType.SVG,
    ))
    grid.add(bar2, grid_opts={'left': '15%', 'bottom': '50%'})
    option1 = grid.dump_options_with_quotes()
    option1 = json.loads(option1)
    grid1 = Grid(init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer=globals.RenderType.SVG,
    ))
    grid1.add(parallel, grid_opts={'left': '30%', 'bottom': '34%'})
    option2 = grid1.dump_options_with_quotes()
    option2 = json.loads(option2)

    option = {"option": [option1, option2], "query": query}
    return option