Esempio n. 1
0
def picture_radar(file_path):
    """
    :param file_path:文件路径:str
    """
    birth_hcs = pd.read_csv(file_path)
    # 使用loc 进行切片, 行:全选  列:选择不连续的用列表包含列名
    birth_nien_hcs = birth_hcs.loc[:, [
        'INFANT_ALIVE_AT_REPORT', 'MOTHER_AGE_YEARS', 'CIG_1_TRI',
        'MOTHER_PRE_WEIGHT', 'OBSTETRIC_GESTATION_WEEKS', 'INFANT_WEIGHT_GRAMS'
    ]]

    birth_nien_hcs = nien_to_nan(birth_nien_hcs, [
        'MOTHER_AGE_YEARS', 'CIG_1_TRI', 'MOTHER_PRE_WEIGHT',
        'OBSTETRIC_GESTATION_WEEKS', 'INFANT_WEIGHT_GRAMS'
    ])

    # birth_nien['INFANT_ALIVE_AT_REPORT'] == 'Y'   判断row的值:等于则为True  再使用DataFrame取为True的行
    y_hcs = birth_nien_hcs[birth_nien_hcs['INFANT_ALIVE_AT_REPORT'] == 'Y']
    n_hcs = birth_nien_hcs[birth_nien_hcs['INFANT_ALIVE_AT_REPORT'] == 'N']
    # 按列求平均值,跳过nan,
    # round(decimals=2): 四舍五入取两位小数
    y_mean_hcs = list(y_hcs.mean(skipna=True, axis=0).round(decimals=2))
    n_mean_hcs = list(n_hcs.mean(skipna=True, axis=0).round(decimals=2))
    print('存活婴儿数据雷达图:', y_mean_hcs, '\n', '死亡婴儿数据雷达图:', n_mean_hcs)
    schema_hcs = [{
        'name': "母亲平均年龄",
        'max': 40
    }, {
        'name': "母亲平均吸烟数量",
        'max': 1.2
    }, {
        'name': "母亲平均体重",
        'max': 200
    }, {
        'name': "怀孕平均周数",
        'max': 40
    }, {
        'name': "婴儿平均体重",
        'max': 3500
    }]
    radar_hcs = Radar('存活婴儿与死亡婴儿数据对比——雷达图(黄彩思)', height=500)
    radar_hcs.set_radar_component(c_schema=schema_hcs)
    radar_hcs.add('存活婴儿', [y_mean_hcs],
                  item_color='#2525f5',
                  symbol=None,
                  area_color='#2525f5',
                  area_opacity=0.3,
                  legend_top='bottom',
                  line_width=3)
    radar_hcs.add('死亡婴儿', [n_mean_hcs],
                  item_color="#f9713c",
                  symbol=None,
                  area_color="#ea3a2e",
                  area_opacity=0.3,
                  legend_top='bottom',
                  line_width=3,
                  legend_text_size=20)
    radar_hcs.render('radar.html')
Esempio n. 2
0
def test_radar_user_define_schema_single():
    radar = Radar("雷达图示例")
    radar.set_radar_component(c_schema=c_schema, shape="circle")
    radar.add("北京", value_bj, item_color="#f9713c", symbol=None)
    radar.add(
        "上海",
        value_sh,
        item_color="#b3e4a1",
        symbol=None,
        legend_selectedmode="single",
    )
    html_content = radar._repr_html_()
    assert "single" in html_content
    assert "multiple" not in html_content
Esempio n. 3
0
def radar_map():
    kwargs = dict(label_text_color=None,
                  is_label_show=True,
                  legend_orient='vertical',
                  legend_pos='right',
                  legend_top='center',
                  legend_text_size=18,
                  label_text_size=18,
                  label_emphasis_textsize=18,
                  xaxis_name_size=18,
                  xaxis_label_textsize=18,
                  xaxis_margin=5,
                  xaxis_line_width=2,
                  yaxis_name_size=18,
                  yaxis_label_textsize=18,
                  yaxis_line_width=2,
                  is_splitline_show=False,
                  is_xaxis_boundarygap=True,
                  is_toolbox_show=False,
                  line_width=3)
    timeline = Timeline(timeline_bottom=0,
                        width=1400,
                        height=700,
                        timeline_symbol_size=10)
    for year in value_base.current_years:
        radar_map = Radar('雷达图',
                          title_pos='center',
                          title_text_size=30,
                          title_top=10)
        for area in value_base.current_areas:
            data = [[]]
            for index in value_base.current_indexs:
                for veti_data in value_base.veti_data_dict[year]:
                    if veti_data[0] == area:
                        data[0].append(
                            round(veti_data[value_base.index_num_dict[index]],
                                  2))
            radar_map.set_radar_component(schema=value_base.radar_schema)
            radar_map.add(area, data, **kwargs)
        timeline.add(radar_map, year)
    result = str(value_base.output_dir + u"雷达图.html")
    timeline.render(result)
Esempio n. 4
0
def test_radar_default_schema():
    schema = [
        ("销售", 6500),
        ("管理", 16000),
        ("信息技术", 30000),
        ("客服", 38000),
        ("研发", 52000),
        ("市场", 25000),
    ]
    v1 = [[4300, 10000, 28000, 35000, 50000, 19000]]
    v2 = [[5000, 14000, 28000, 31000, 42000, 21000]]
    radar = Radar("雷达图示例")
    radar.set_radar_component(schema)
    radar.add("预算分配", v1, is_splitline=True, is_axisline_show=True)
    radar.add(
        "实际开销",
        v2,
        label_color=["#4e79a7"],
        is_area_show=False,
        legend_selectedmode="single",
    )
    radar.render()