def drawer2(stage_name, data):
    c_schema = [
        {
            "name": "乐",
            "max": 0.55,
            "min": 0
        },
        {
            "name": "好",
            "max": 0.55,
            "min": 0
        },
        {
            "name": "哀",
            "max": 0.55,
            "min": 0
        },
        {
            "name": '恶',
            "max": 0.55,
            "min": 0
        },
        {
            "name": "惧",
            "max": 0.55,
            "min": 0
        },
    ]
    c = (Radar().set_colors(["#CC3300"]).add_schema(
        schema=c_schema,
        shape="circle",
        center=["50%", "50%"],
        radius="80%",
        angleaxis_opts=opts.AngleAxisOpts(
            min_=0,
            max_=360,
            is_clockwise=False,
            interval=5,
            axistick_opts=opts.AxisTickOpts(is_show=False),
            axislabel_opts=opts.LabelOpts(is_show=False),
            axisline_opts=opts.AxisLineOpts(is_show=False),
            splitline_opts=opts.SplitLineOpts(is_show=False),
        ),
        radiusaxis_opts=opts.RadiusAxisOpts(
            min_=-4,
            max_=4,
            interval=2,
            splitarea_opts=opts.SplitAreaOpts(
                is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)),
        ),
        polar_opts=opts.PolarOpts(),
        splitarea_opt=opts.SplitAreaOpts(is_show=False),
        splitline_opt=opts.SplitLineOpts(is_show=False),
    ).add(
        series_name=stage_name,
        data=data,
        areastyle_opts=opts.AreaStyleOpts(opacity=0.1),
        linestyle_opts=opts.LineStyleOpts(width=3),
    ).render("res\\output\\multi-emotion\\image\\" + stage_name + ".html"))
Exemplo n.º 2
0
def test_radar_options(fake_writer):
    c = (Radar().add_schema(
        schema=[
            opts.RadarIndicatorItem(name="销售", max_=6500),
            opts.RadarIndicatorItem(name="管理", max_=16000),
            opts.RadarIndicatorItem(name="信息技术", max_=30000),
            opts.RadarIndicatorItem(name="客服", max_=38000),
            opts.RadarIndicatorItem(name="研发", max_=52000),
            opts.RadarIndicatorItem(name="市场", max_=25000),
        ],
        radiusaxis_opts=opts.RadiusAxisOpts(),
        angleaxis_opts=opts.AngleAxisOpts(),
        polar_opts=opts.PolarOpts(),
    ).add("预算分配", v1).add(
        "实际开销", v2).set_series_opts(label_opts=opts.LabelOpts(is_show=False)))
    c.render()
    _, content = fake_writer.call_args[0]
    assert_in("radiusAxis", content)
    assert_in("angleAxis", content)
    assert_in("polar", content)
Exemplo n.º 3
0
def radar_angle_radius_axis_opts() -> Radar:
    data = [
        {
            "value": [4, -4, 2, 3, 0, 1],
            "name": "预算分配"
        },
    ]
    c_schema = [
        {
            "name": "销售",
            "max": 4,
            "min": -4
        },
        {
            "name": "管理",
            "max": 4,
            "min": -4
        },
        {
            "name": "技术",
            "max": 4,
            "min": -4
        },
        {
            "name": "客服",
            "max": 4,
            "min": -4
        },
        {
            "name": "研发",
            "max": 4,
            "min": -4
        },
        {
            "name": "市场",
            "max": 4,
            "min": -4
        },
    ]
    c = (Radar().set_colors(["#4587E7"]).add_schema(
        schema=c_schema,
        shape="circle",
        center=["50%", "50%"],
        radius="80%",
        angleaxis_opts=opts.AngleAxisOpts(
            min_=0,
            max_=360,
            is_clockwise=False,
            interval=5,
            axistick_opts=opts.AxisTickOpts(is_show=False),
            axislabel_opts=opts.LabelOpts(is_show=False),
            axisline_opts=opts.AxisLineOpts(is_show=False),
            splitline_opts=opts.SplitLineOpts(is_show=False),
        ),
        radiusaxis_opts=opts.RadiusAxisOpts(
            min_=-4,
            max_=4,
            interval=2,
            splitarea_opts=opts.SplitAreaOpts(
                is_show=True,
                areastyle_opts=opts.AreaStyleOpts(opacity=1),
            )),
        polar_opts=opts.PolarOpts(),
        splitarea_opt=opts.SplitAreaOpts(is_show=False),
        splitline_opt=opts.SplitLineOpts(is_show=False),
    ).add(
        series_name="预算",
        data=data,
        areastyle_opts=opts.AreaStyleOpts(opacity=0.1),
        linestyle_opts=opts.LineStyleOpts(width=1),
    ))
    return c
Exemplo n.º 4
0
c = (Radar().set_colors(["#4587E7"]).add_schema(
    schema=c_schema,
    shape="circle",
    center=["50%", "50%"],
    radius="80%",
    angleaxis_opts=opts.AngleAxisOpts(
        min_=0,
        max_=360,
        is_clockwise=False,
        interval=5,
        axistick_opts=opts.AxisTickOpts(is_show=False),
        axislabel_opts=opts.LabelOpts(is_show=False),
        axisline_opts=opts.AxisLineOpts(is_show=False),
        splitline_opts=opts.SplitLineOpts(is_show=False),
    ),
    radiusaxis_opts=opts.RadiusAxisOpts(
        min_=-4,
        max_=4,
        interval=2,
        splitarea_opts=opts.SplitAreaOpts(
            is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)),
    ),
    polar_opts=opts.PolarOpts(),
    splitarea_opt=opts.SplitAreaOpts(is_show=False),
    splitline_opt=opts.SplitLineOpts(is_show=False),
).add(
    series_name="预算",
    data=data,
    areastyle_opts=opts.AreaStyleOpts(opacity=0.1),
    linestyle_opts=opts.LineStyleOpts(width=1),
).render("Radar_angle_radius_axis.html"))
Exemplo n.º 5
0
def Radar_pic(name, datas, ifratio) -> Radar:
    color = ["#ff7f00"] if ifratio else ["#4587E7"]
    data = [{"value": datas, "name": name}]
    watermax = 1000 if datas[0] < 1000 else datas[0] * 1.1
    mountainmax = 1000 if datas[1] < 1000 else datas[1] * 1.1
    corridormax = 1000 if datas[2] < 1000 else datas[2] * 1.1
    secondmax = 250 if datas[3] < 250 else datas[3] * 1.1
    intermax = 500 if datas[4] < 500 else datas[4] * 1.1
    landscapemax = 250 if datas[5] < 250 else datas[5] * 1.1
    mainmax = 250 if datas[6] < 250 else datas[6] * 1.1
    othermax = 450 if datas[7] < 450 else datas[7] * 1.1

    waterratio = 0.25 if datas[0] < 0.25 else datas[0] * 1.2
    mountainratio = 0.25 if datas[1] < 0.25 else datas[1] * 1.1

    c_schema = [
        {
            "name": "主水",
            "max": round(waterratio, 2) if ifratio else round(watermax)
        },
        {
            "name": "主山",
            "max": round(mountainratio, 2) if ifratio else round(mountainmax)
        },
        {
            "name": "廊道",
            "max": 0.25 if ifratio else round(corridormax)
        },
        {
            "name": "次路",
            "max": 0.20 if ifratio else round(secondmax)
        },
        {
            "name": "夹层",
            "max": 0.20 if ifratio else round(intermax)
        },
        {
            "name": "主景观建筑",
            "max": 0.20 if ifratio else round(landscapemax)
        },
        {
            "name": "主厅",
            "max": 0.20 if ifratio else round(mainmax)
        },
        {
            "name": "其他建筑",
            "max": 0.20 if ifratio else round(othermax)
        },
    ]

    c = (
        Radar().set_colors(color).add_schema(
            schema=c_schema,
            shape="circle",
            # 图片中心位置
            center=["50%", "50%"],
            # 雷达图半径大小
            radius="80%",
            angleaxis_opts=opts.AngleAxisOpts(
                # 径向轴大小
                # min_=0,
                # max_=360,
                # is_clockwise=False,
                # 径向轴间隔大小
                interval=4,
                axistick_opts=opts.AxisTickOpts(is_show=False),
                axislabel_opts=opts.LabelOpts(is_show=False),
                axisline_opts=opts.AxisLineOpts(is_show=False),
                splitline_opts=opts.SplitLineOpts(is_show=False),
            ),
            textstyle_opts=opts.TextStyleOpts(font_size=20),
            radiusaxis_opts=opts.RadiusAxisOpts(
                min_=0,
                max_=1000,
                interval=200,
                splitarea_opts=opts.SplitAreaOpts(
                    is_show=False,
                    areastyle_opts=opts.AreaStyleOpts(opacity=1)),
            ),
            polar_opts=opts.PolarOpts(),
            splitarea_opt=opts.SplitAreaOpts(is_show=False),
            splitline_opt=opts.SplitLineOpts(is_show=False),
        ).add(
            series_name=name,
            data=data,
            # 透明度
            areastyle_opts=opts.AreaStyleOpts(opacity=0.2),
            # 线宽
            linestyle_opts=opts.LineStyleOpts(width=2),
            label_opts=opts.LabelOpts(font_size=20)).set_global_opts(
                title_opts=opts.TitleOpts(
                    title=name,
                    pos_left="22%",
                    pos_top="10",
                ),
                legend_opts=opts.LegendOpts(pos_right=10)))
    return c
Exemplo n.º 6
0
    def view_radar(self, df_view):
        """
            画雷达图
            
            例子:
                page_ = Page()
                for v in view_lst:
                    view_label[1] = v
                    df_view = get_view_dt(df_all, 'label', view_label, call_cols, call_dct)
                    c = view_radar(df_view)
                    page_.add(c)
                    print(f'Finished {v}')
                print('Finished all')  
                page_.render_notebook()
            """
        c_schema = []
        try:
            add_name1, add_name2 = df_view.columns[1], df_view.columns[2]
            add_value1, add_value2 = [
                df_view.iloc[list(range(12)), 1].tolist()
            ], [df_view.iloc[list(range(12)), 2].tolist()]
            max_v = max(max(add_value1[0]), max(add_value2[0]))
            min_v = min(min(add_value1[0]), min(add_value2[0]))
            max_v_set = 1 if max_v > 0.65 else max_v + min_v
            for i in df_view.loc[list(range(12)), 'index']:
                c_schema.append({"name": i, "max": max_v_set, "min": 0})
        except:
            add_name1, add_name2 = df_view.columns[1], df_view.columns[2]
            add_value1, add_value2 = [df_view.iloc[:, 1].tolist()
                                      ], [df_view.iloc[:, 2].tolist()]
            max_v = max(max(add_value1[0]), max(add_value2[0]))
            min_v = min(min(add_value1[0]), min(add_value2[0]))
            max_v_set = 1 if max_v > 0.65 else max_v + min_v
            for i in df_view.loc[:, 'index']:
                c_schema.append({"name": i, "max": max_v_set, "min": 0})

        c = (Radar().add_schema(
            c_schema,
            shape="circle",
            center=["50%", "50%"],
            radius="80%",
            angleaxis_opts=opts.AngleAxisOpts(
                min_=0,
                max_=360,
                is_clockwise=False,
                interval=5,
                axistick_opts=opts.AxisTickOpts(is_show=False),
                axislabel_opts=opts.LabelOpts(is_show=False),
                axisline_opts=opts.AxisLineOpts(is_show=False),
                splitline_opts=opts.SplitLineOpts(is_show=False),
            ),
            radiusaxis_opts=opts.RadiusAxisOpts(
                min_=0,
                max_=round(max_v_set, 3),
                interval=round(max_v_set / 5, 3),
                splitarea_opts=opts.SplitAreaOpts(
                    is_show=True,
                    areastyle_opts=opts.AreaStyleOpts(opacity=1)),
            ),
            polar_opts=opts.PolarOpts(),
            splitarea_opt=opts.SplitAreaOpts(is_show=False),
            splitline_opt=opts.SplitLineOpts(is_show=False),
        ).add(add_name1, add_value1, color="#f9713c").add(
            add_name2,
            add_value2,
            color="#b3e4a1",
            areastyle_opts=opts.AreaStyleOpts(opacity=0.3)).set_series_opts(
                label_opts=opts.LabelOpts(is_show=False)))

        return c
Exemplo n.º 7
0
def draw_radar(season_x, season_name, filechart, seasonareacolor, seasonlinecolor):
    # 建立schema的json文件  season_x.columns = [season_name]
    season_index = season_x.index.to_list()
    # print(season_index)
    # n_max, n_min = max(season_x), min(season_x)
    n_max = max(enumerate(season_x[0]), key=operator.itemgetter(1))[1]
    n_min = min(enumerate(season_x[0]), key=operator.itemgetter(1))[1]
    # 用于获取对象的哪些维的数据
    # print(n_max, n_min)
    df_season = pd.DataFrame({'name': season_index})
    df_season['max'], df_season['min'] = n_max, n_min
    # season_js = df_season.to_json(orient='records')
    # print(season_js)
    # 设置16方位, 逆时针排序
    season_js = [
        {"name": "N", "max": n_max, "min": n_min},
        {"name": "NNW", "max": n_max, "min": n_min},
        {"name": "NW", "max": n_max, "min": n_min},
        {"name": "WNW", "max": n_max, "min": n_min},
        {"name": "W", "max": n_max, "min": n_min},
        {"name": "WSW", "max": n_max, "min": n_min},
        {"name": "SW", "max": n_max, "min": n_min},
        {"name": "SSW", "max": n_max, "min": n_min},
        {"name": "S", "max": n_max, "min": n_min},
        {"name": "SSE", "max": n_max, "min": n_min},
        {"name": "SE", "max": n_max, "min": n_min},
        {"name": "ESE", "max": n_max, "min": n_min},
        {"name": "E", "max": n_max, "min": n_min},
        {"name": "ENE", "max": n_max, "min": n_min},
        {"name": "NE", "max": n_max, "min": n_min},
        {"name": "NNE", "max": n_max, "min": n_min},
    ]
    # 设置数据
    fengsus = season_x[0].to_list()
    data_fengsu = [{'value': fengsus, 'name': '风频数'}]
    # print(data_fengsu)
    charts = Radar()
    charts.set_colors(['#4587E7'])  # 设置颜色
    charts.add_schema(schema=season_js,
                      shape='circle',
                      center=['50%', '50%'],
                      radius='80%',
                      angleaxis_opts=opts.AngleAxisOpts(
                          min_=0,  # 坐标轴刻度最小值
                          max_=360,  # 坐标轴刻度最大值
                          is_clockwise=True,
                          interval=22.5,  # 强制设置坐标轴分割间隔
                          axistick_opts=opts.AxisTickOpts(is_show=False),
                          axislabel_opts=opts.LabelOpts(is_show=False,),   # 坐标轴线标签配置项
                          axisline_opts=opts.AxisLineOpts(is_show=True),  # 坐标轴线风格配置项
                          splitline_opts=opts.SplitLineOpts(is_show=True)  # 分割线配置项
                      ),
                      radiusaxis_opts=opts.RadiusAxisOpts(
                          min_=n_min,  # 坐标轴刻度最小值
                          max_=n_max,   # 坐标轴刻度最大值
                          interval=2,  # 强制设置坐标轴分割间隔
                          splitarea_opts=opts.SplitAreaOpts(
                              is_show=True,
                              areastyle_opts=opts.AreaStyleOpts(opacity=0.2,
                                                                )
                          ),
                          splitline_opts=opts.SplitLineOpts(is_show=True,
                                                            linestyle_opts=opts.LineStyleOpts(is_show=True,
                                                                                              width=0.5,
                                                                                              color='grey')),
                          axislabel_opts=opts.LabelOpts(is_show=True,
                                                        font_size=12,
                                                        color='grey'),  # 坐标轴线标签配置项
                      ),
                      polar_opts=opts.PolarOpts(),
                      splitarea_opt=opts.SplitAreaOpts(is_show=True),
                      splitline_opt=opts.SplitLineOpts(is_show=False),  # 分割线配置项
                      textstyle_opts=opts.TextStyleOpts(color='black',
                                                        font_size=14)
                      )
    charts.add(series_name='%s玫瑰图' % season_name,  # 系列名称
               data=data_fengsu,  # 系列数据
               areastyle_opts=opts.AreaStyleOpts(opacity=0.5,  # 系列面样式设置
                                                 color=seasonareacolor),
               linestyle_opts=opts.LineStyleOpts(width=2,  # 系列线样式设置
                                                 color=seasonlinecolor),
               label_opts=opts.LabelOpts(is_show=False),
               )  # 系列标签设置
    charts.render(filechart)