コード例 #1
0
ファイル: Graph.py プロジェクト: zan-lab/EasyVisualData
    def getRadar(self, sheet: xlrd.sheet) -> Radar:
        namelist = sheet.col_values(0, 1)
        maxvaluelist = sheet.col_values(1, 1)
        maxlist = [
            opts.RadarIndicatorItem(name=namelist[i], max_=maxvaluelist[i])
            for i in range(len(namelist))
        ]
        valuelists = dict()
        for i in range(2, sheet.ncols):
            valuelists[sheet.cell(0, i).value] = sheet.col_values(i, 1)
        r = Radar()
        r.add_schema(
            schema=maxlist,
            splitarea_opt=opts.SplitAreaOpts(
                is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)),
            textstyle_opts=opts.TextStyleOpts(color="#fff"),
        )
        #设置颜色的列表
        colorstr = ["#CD0000", "#5CACEE", "#7B68EE", "#FFFF00"]
        colorth = 0
        for name, values in valuelists.items():
            r.add(
                series_name=name,
                data=values,
                linestyle_opts=opts.LineStyleOpts(color=colorstr[colorth]),
            )
            colorth = (colorth + 1) % len(colorstr)  #颜色循环

        r.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        r.set_global_opts(title_opts=opts.TitleOpts(
            title=sheet.name,
            title_textstyle_opts=opts.TextStyleOpts(color="#fff")),
                          legend_opts=opts.LegendOpts())
        return r
コード例 #2
0
def year_store_order_base():
    # 不同门店的年营业额数据查询
    dataX, dataY1, dataY2 = year_store_query()
    # 对象声明
    radar = Radar(init_opts=opts.InitOpts(
        width="1280px", height="720px", bg_color="#CCCCCC"))
    radar.add_schema(
        schema=[
            opts.RadarIndicatorItem(name="门店订单金额", max_=34000),
            opts.RadarIndicatorItem(name="门店顾客数", max_=10000),
            opts.RadarIndicatorItem(name="门店商品类型", max_=10000),
            opts.RadarIndicatorItem(name="门店订单量", max_=10000)
        ],
        splitarea_opt=opts.SplitAreaOpts(
            is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)),
        textstyle_opts=opts.TextStyleOpts(color="#fff"),
    )
    radar.add(
        series_name="Store 1",
        data=[list(dataY1)],
        linestyle_opts=opts.LineStyleOpts(color="#CD0000"),
    )
    radar.add(
        series_name="Store 2",
        data=[list(dataY2)],
        linestyle_opts=opts.LineStyleOpts(color="#5CACEE"),
    )
    radar.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    radar.set_global_opts(title_opts=opts.TitleOpts(title="2005年门店竞争优势多维分析"),
                          legend_opts=opts.LegendOpts())
    return radar
コード例 #3
0
def drawRadar(arr, value, valuemax, name):
    radar = Radar(init_opts=opts.InitOpts(
        width="1280px", height="720px", bg_color="#CCCCCC"))
    v_max = [list(z) for z in zip(arr, valuemax)]
    radar.add_schema(
        schema=[opts.RadarIndicatorItem(name=k, max_=v) for k, v in v_max],
        splitarea_opt=opts.SplitAreaOpts(
            is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)),
        textstyle_opts=opts.TextStyleOpts(color="#fff"),
    )
    radar.add(
        series_name=name,
        data=value,
        linestyle_opts=opts.LineStyleOpts(color="#CD0000"),
    )
    radar.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    radar.set_global_opts(title_opts=opts.TitleOpts(title=name),
                          legend_opts=opts.LegendOpts())
    radar.render("{0}.html".format(name))
コード例 #4
0
def DrawRadar(title, data, savepath):
    print('正在分析评分构成...')
    radar = Radar()
    radar.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    radar.set_global_opts(
        title_opts=opts.TitleOpts(title="Radar-评分分布统计雷达图", pos_left='center'),
        legend_opts=opts.LegendOpts(orient="vertical",
                                    pos_top="middle",
                                    pos_left="2%"),
    )
    values = [[data[i][1] for i in range(len(data))]]  # 把整个列表当做一个要画的东西
    attrs = [data[i][0] for i in range(len(data))]  # 改名字
    attrs = list(map(int, attrs))
    attrs = [str(i) + '星' for i in attrs]
    num = len(attrs)  # 雷达图有几项
    schema = [{"name": attrs[i], "max": 230} for i in (range(num))]
    radar.add_schema(schema=schema)
    radar.add('豆瓣评分构成', values)
    radar.render(os.path.join(savepath, '%s.html' % title))
コード例 #5
0
def draw_radar_for_observation_result():
    value = [[43, 58, 78, 65, 86, 63]]
    min_val = 0
    max_val = 100

    # 用于调整雷达各维度的范围大小
    c_schema = [{"name": "交往能力", "max": max_val, "min": min_val, },
                {"name": "感知能力", "max": max_val, "min": min_val, "color": "#ff0000"},
                {"name": "运动能力", "max": max_val, "min": min_val, "color": "#000000"},
                {"name": "注意力", "max": max_val, "min": min_val, "color": "#00ffff"},
                {"name": "语言能力", "max": max_val, "min": min_val, "color": "#ff00ff"},
                {"name": "自我照顾能力", "max": max_val, "min": min_val, "color": "#ff00ff"}
                ]

    # 画图
    radar = Radar()
    radar.add_schema(c_schema, textstyle_opts=opts.TextStyleOpts(color="#3344ff"))
    radar.add(None, value, color="#f9713c",
              symbol='circle', label_opts=opts.LabelOpts(is_show=True),
              areastyle_opts=opts.AreaStyleOpts(opacity=0.5, color="#f9713c"))
    radar.set_global_opts(title_opts=opts.TitleOpts(title="Radar-基本示例"))

    radar.render("observation_result.html")
コード例 #6
0
        connection.close()
# 执行主函数
if __name__ == '__main__':
    print(store_query())
    data1, data2, data3 = store_query()
    radar = Radar(init_opts=opts.InitOpts(theme=ThemeType.DARK,width="1280px", height="720px"))
    radar.add_schema(schema=[
        opts.RadarIndicatorItem(name="门店订单金额", max_=50000),
        opts.RadarIndicatorItem(name="门店订单量", max_=10000),
        opts.RadarIndicatorItem(name="门店顾客数", max_=10000),
        opts.RadarIndicatorItem(name="门店商品类型", max_=10000),
    ],
    splitarea_opt=opts.SplitAreaOpts(
    is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)
    ),
    textstyle_opts=opts.TextStyleOpts(color="#fff"),
    )
    radar.add(series_name="1号门店",
              data=[list(data1)],
              linestyle_opts=opts.LineStyleOpts(color="#CD0000")
              )
    radar.add(series_name="2号门店",
              data=[list(data2)],
              linestyle_opts=opts.LineStyleOpts(color="#5CACEE")
              )
    radar.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    radar.set_global_opts(
        title_opts=opts.TitleOpts(title="门店竞争优势多维分析"), legend_opts=opts.LegendOpts()
    )
    radar.render('radar.html')
コード例 #7
0
# 雷达图
v1 = [[4300, 10000, 28000, 35000, 50000, 19000],
      [3300, 13000, 25000, 30000, 48000, 24000]]
v2 = [[5000, 14000, 28000, 31000, 42000, 21000]]
radar = Radar()
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),
])
radar.add('预算分配', v1)
radar.add('实际开销', v2)
radar.set_global_opts(title_opts=opts.TitleOpts(title='Radar Sample'))
radar.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
radar.render('pyecharts-radar.html')

# 词云图
words = [
    ('Sam S Club', 10000),
    ('Macys', 6181),
    ('Amy Schumer', 4386),
    ('Jurassic World', 4055),
    ('Charter Communications', 2467),
]
wordcloud = WordCloud()
wordcloud.add('', words, word_size_range=[20, 100])
wordcloud.set_global_opts(title_opts=opts.TitleOpts(title='WordCloud Sample'))
wordcloud.render('pyecharts-wordcloud.html')
コード例 #8
0
def dsp_bv():  # 显示育种值

    import xlrd
    prepare = locals()
    # file = "breeding.xlsx"
    f1 = xlrd.open_workbook(file)
    sheet1 = f1.sheet_by_name('Sheet1')
    radar = Radar(init_opts=opts.InitOpts(
        width="1280px",
        height="720px",
        #bg_color='rgba(255,250,205,0.2)'
    ))

    lst1 = bv(file)[0]  # 接收计算的给性状各公牛的育种值
    lst2 = bv(file)[1]  # 公牛编号
    lst3 = bv(file)[2]  # 性状名
    for i in range(len(lst1[0])):  # 初始化各公牛的个性状育种值列表(每个列表代表一头公牛个性状的育种值)
        prepare["blupscore" + str(i)] = []

    for i in range(len(lst2)):  # 公牛编号
        for j in range(len(lst3)):  # 性状
            prepare["blupscore" + str(i)].append(round(lst1[j][i], 4))
    scoreprint = [[] for i in range(3)]
    for i in range(len(lst2)):
        scoreprint[i].append(prepare["blupscore" + str(i)])
    # for i in range(len(lst2)):
    #     print(scoreprint[i])
    # lst3 = cbv(file)[2]
    radar.add_schema(schema=[
        opts.RadarIndicatorItem(name="体重", max_=10, min_=-10),
        opts.RadarIndicatorItem(name="体高", max_=10, min_=-10),
        opts.RadarIndicatorItem(name="体长", max_=10, min_=-10),
        opts.RadarIndicatorItem(name="胸围", max_=10, min_=-10),
        opts.RadarIndicatorItem(name="眼肌面积", max_=10, min_=-10)
    ],
                     splitarea_opt=opts.SplitAreaOpts(
                         is_show=True,
                         areastyle_opts=opts.AreaStyleOpts(opacity=1)),
                     textstyle_opts=opts.TextStyleOpts(color="black"))
    color = ["red", "blue", "green", "black", "purple"]
    for i in range(len(lst2)):
        radar.add(series_name=str(int(lst2[i])),
                  data=scoreprint[i],
                  color=color[i]
                  )  # series_name的value要为str类型,否则不会显示opts.LegendOpts()效果
    # radar.add(series_name=str(lst2[0]), data=scoreprint[0], color=color[0])
    # radar.add(series_name=str(lst2[1]), data=scoreprint[1], color=color[1])
    radar.set_global_opts(title_opts=opts.TitleOpts(title="显示已有数据的各公牛的性状育种值"),
                          legend_opts=opts.LegendOpts())

    # v1 = [[4300, 10000, 28000, 35000, 50000, 19000]]
    # v2 = [[5000, 14000, 28000, 31000, 42000, 21000]]
    # 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),
    #         ]
    #     )
    #         .add("预算分配", v1)
    #         .add("实际开销", v2)
    #         .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    #         .set_global_opts(
    #         legend_opts=opts.LegendOpts(selected_mode="single"),
    #         title_opts=opts.TitleOpts(title="Radar-单例模式"),
    #     ))
    # radar.render("display.html")
    picture = radar
    return render_template("display.html",
                           picture_options=picture.dump_options())
コード例 #9
0
ファイル: work.py プロジェクト: zhurui-king/little-pig
def  Cartography():

    #创建地图
    map = Map( init_opts=opts.InitOpts(width="1900px", height="900px", bg_color="#d0effa", page_title="全球新冠疫情_1"))
    map.add("确诊人数",[list(z) for z in zip(names_new, confirm)],is_map_symbol_show=False,
            maptype="world",label_opts=opts.LabelOpts(is_show=False),itemstyle_opts=opts.ItemStyleOpts(color="rgb(98,121,146)"))#地图区域颜色
    map.set_global_opts(title_opts = opts.TitleOpts(title='全球新冠疫情确诊人数'),legend_opts=opts.LegendOpts(is_show=False),
                     visualmap_opts=opts.VisualMapOpts(max_=2000000, is_piecewise=True,
                                      pieces=[
                                        {"max": 3000000,"min": 500001,"label":">500000","color":"#460303"},
                                        {"max": 500000, "min": 100001, "label": "100001-500000", "color": "#8A0808"},
                                        {"max": 100000, "min": 10001, "label": "10001-100000", "color": "#B40404"},
                                        {"max": 10000, "min": 1001, "label": "1001-10000", "color": "#DF0101"},
                                        {"max": 1000, "min": 101, "label": "101-1000", "color": "#F78181"},
                                        {"max": 100, "min": 1, "label": "1-100", "color": "#F5A9A9"},
                                        {"max": 0, "min": 0, "label": "0", "color": "#fababa"},
                                        ])  
                     )
    map.render('Global_new_crown_epidemic_map.html')

        #创建饼图
    pie = Pie(init_opts=opts.InitOpts(width='1900px', height='900px',page_title="全球新冠疫情_2",bg_color="#fee4e7"))
    # 添加数据
    pie.add("", [list(z) for z in zip(country_list, dead_list)],
            radius=['20%', '100%'],#设置内径外径
            center=['60%', '65%'],
            rosetype='area')#圆心角相同,通过半径展现数据大小#rosetype='radius'圆心角展现数据百分比,半径展现数据大小
    
    # 设置全局配置
    pie.set_global_opts(title_opts=opts.TitleOpts(title='全球新冠疫情',subtitle='死亡人数超过\n5000的国家\n  (除中国)',
                                               title_textstyle_opts=opts.TextStyleOpts(font_size=15,color= '#f40909'),
                                               subtitle_textstyle_opts= opts.TextStyleOpts(font_size=15,color= '#8a0b0b'),
                                               pos_right= 'center',pos_left= '57%',pos_top= '60%',pos_bottom='center'),
                                legend_opts=opts.LegendOpts(is_show=False))
    # 设置系列配置和颜色
    pie.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='inside', font_size=13,
                                              formatter='{b}:{c}', font_style='italic',
                                              font_family='Microsoft YaHei'))
    pie.set_colors(color_matching)
    pie.render('Global_new_crown_epidemic_Rose.html')

    #创建雷达图
    radar = Radar(init_opts=opts.InitOpts(width='1900px',height='900px',page_title="全球新冠疫情_3",bg_color="#d1eff3"))
    #由于雷达图传入的数据得为多维数据,所以这里需要做一下处理
    radar_data1 = [list(dead_list)]
    radar_data2 = [list(heal_list)]
    radar.add_schema(
            schema=[
                opts.RadarIndicatorItem(name='巴西', max_=8000),
                opts.RadarIndicatorItem(name='荷兰', max_=8000),
                opts.RadarIndicatorItem(name='伊朗', max_=20000),
                opts.RadarIndicatorItem(name='德国', max_=40000),
                opts.RadarIndicatorItem(name='比利时', max_=70000),
                opts.RadarIndicatorItem(name='英国', max_=80000),
                opts.RadarIndicatorItem(name='法国 ', max_=110000),
                opts.RadarIndicatorItem(name='西班牙', max_=150000),
                opts.RadarIndicatorItem(name='意大利', max_=170000),
                opts.RadarIndicatorItem(name='美国', max_=220000),
            ]
        )
    radar.add("死亡人数",radar_data1,color='blue',areastyle_opts = opts.AreaStyleOpts(opacity = 0.2,color='blue'))
    radar.add("治愈人数",radar_data2,color='red',areastyle_opts=opts.AreaStyleOpts(opacity=0.3,color='red'))
    radar.set_series_opts(label_opts=opts.LabelOpts(is_show=True))
    radar.set_global_opts(title_opts=opts.TitleOpts(title="死亡人数与治愈人数对比")) 
    radar.render("Death_Versus_Heal.html")
コード例 #10
0
def plt(key):
    """连接hbase"""
    connection = happybase.Connection(host="localhost", port=9090)
    """打开传输"""
    connection.open()
    """连接表"""
    basicFeaturesTable = happybase.Table('basicFeaturesTable', connection)
    socialAttributesTable = happybase.Table('socialAttributesTable',
                                            connection)
    consumptionFeaturesTable = happybase.Table('consumptionFeaturesTable',
                                               connection)
    internetFeaturesTable = happybase.Table('internetFeaturesTable',
                                            connection)
    consumptionCharacteristicsTable = happybase.Table(
        'consumptionCharacteristicsTable', connection)
    internetBehaviorTable = happybase.Table('internetBehaviorTable',
                                            connection)
    """获取信息"""
    try:
        key_name = basicFeaturesTable.row(key, columns=["name"])
    except:
        """连接hbase"""
        connection = happybase.Connection(host="localhost", port=9090)
        """打开传输"""
        connection.open()
        """连接表"""
        basicFeaturesTable = happybase.Table('basicFeaturesTable', connection)
        socialAttributesTable = happybase.Table('socialAttributesTable',
                                                connection)
        consumptionFeaturesTable = happybase.Table('consumptionFeaturesTable',
                                                   connection)
        internetFeaturesTable = happybase.Table('internetFeaturesTable',
                                                connection)
        consumptionCharacteristicsTable = happybase.Table(
            'consumptionCharacteristicsTable', connection)
        internetBehaviorTable = happybase.Table('internetBehaviorTable',
                                                connection)

        key_name = basicFeaturesTable.row(key, columns=["name"])

    key_name = list(key_name.values())
    key_name = key_name[0].decode()

    try:
        sInfo = socialAttributesTable.row(key,
                                          columns=["incLevel", "eduLevel"])
        cInfo = consumptionFeaturesTable.row(key,
                                             columns=["CMLevel", "CTLevel"])
        iInfo = internetFeaturesTable.row(key, columns=["intLevel"])
        consumptionCharacteristicsInfo = consumptionCharacteristicsTable.row(
            key, columns=["commodity", "price", "date"])
        internetBehaviorInfo = internetBehaviorTable.row \
            (key, columns=
            ["date", "news", "communications", "entertainment", "domersticServices", "busApp", "toolUse"]
             )
    except:
        """连接hbase"""
        connection = happybase.Connection(host="localhost", port=9090)
        """打开传输"""
        connection.open()
        """连接表"""
        basicFeaturesTable = happybase.Table('basicFeaturesTable', connection)
        socialAttributesTable = happybase.Table('socialAttributesTable',
                                                connection)
        consumptionFeaturesTable = happybase.Table('consumptionFeaturesTable',
                                                   connection)
        internetFeaturesTable = happybase.Table('internetFeaturesTable',
                                                connection)
        consumptionCharacteristicsTable = happybase.Table(
            'consumptionCharacteristicsTable', connection)
        internetBehaviorTable = happybase.Table('internetBehaviorTable',
                                                connection)

        sInfo = socialAttributesTable.row(key,
                                          columns=["incLevel", "eduLevel"])
        cInfo = consumptionFeaturesTable.row(key,
                                             columns=["CMLevel", "CTLevel"])
        iInfo = internetFeaturesTable.row(key, columns=["intLevel"])
        consumptionCharacteristicsInfo = consumptionCharacteristicsTable.row(
            key, columns=["commodity", "price", "date"])
        internetBehaviorInfo = internetBehaviorTable.row \
            (key, columns=
            ["date", "news", "communications", "entertainment", "domersticServices", "busApp", "toolUse"]
             )
    """消费情况图"""
    consumptionCharacteristicsValues = list(
        consumptionCharacteristicsInfo.values())
    consumptionCharacteristicsValues = list(
        map(lambda x: x.decode(), consumptionCharacteristicsValues))

    consumptionCharacteristicsValues[
    int(len(consumptionCharacteristicsValues) / 3):-int(len(consumptionCharacteristicsValues) / 3)] \
        = list(map(int, consumptionCharacteristicsValues[int(len(consumptionCharacteristicsValues) / 3):
                                                         -int(len(consumptionCharacteristicsValues) / 3)]))
    consumptionCharacteristicsValues[-int(len(consumptionCharacteristicsValues) / 3):] \
        = list(map(int, consumptionCharacteristicsValues[-int(len(consumptionCharacteristicsValues) / 3):]))

    consumptionCharacteristicsData = []
    consumptionCharacteristicsData.append(
        consumptionCharacteristicsValues[:int(
            len(consumptionCharacteristicsValues) / 3)])
    consumptionCharacteristicsData.append(consumptionCharacteristicsValues[
        int(len(consumptionCharacteristicsValues) /
            3):-int(len(consumptionCharacteristicsValues) / 3)])
    consumptionCharacteristicsData.append(consumptionCharacteristicsValues[
        -int(len(consumptionCharacteristicsValues) / 3):])

    consumptionCharacteristicsData = pd.DataFrame(
        consumptionCharacteristicsData).T
    consumptionCharacteristicsData.columns = ["commodity", "date", "price"]
    consumptionCharacteristicsData.sort_values(by="date", inplace=True)
    consumptionCharacteristicsData_y = consumptionCharacteristicsData.loc[:,
                                                                          "date"].tolist(
                                                                          )
    consumptionCharacteristicsData_y = list(
        map(str, consumptionCharacteristicsData_y))
    consumptionCharacteristicsData_x = consumptionCharacteristicsData.loc[:,
                                                                          "price"].tolist(
                                                                          )
    consumptionCharacteristicsData_commodity = consumptionCharacteristicsData.loc[:,
                                                                                  "commodity"].tolist(
                                                                                  )

    quzhong_consumptionCharacteristicsData_y = list(
        set(consumptionCharacteristicsData_y))
    if len(quzhong_consumptionCharacteristicsData_y) != len(
            consumptionCharacteristicsData_y):
        for i in range(len(quzhong_consumptionCharacteristicsData_y)):
            count_consumptionCharacteristicsData_y = consumptionCharacteristicsData_y. \
                count(quzhong_consumptionCharacteristicsData_y[i])
            if count_consumptionCharacteristicsData_y != 1:
                index = consumptionCharacteristicsData_y.index(
                    quzhong_consumptionCharacteristicsData_y[i])
                consumptionCharacteristicsData_y = consumptionCharacteristicsData_y[:index + 1] + \
                                                   consumptionCharacteristicsData_y[
                                                   index + count_consumptionCharacteristicsData_y:]
                consumptionCharacteristicsData_x[index] = sum(
                    consumptionCharacteristicsData_x[
                        index:index + count_consumptionCharacteristicsData_y])
                consumptionCharacteristicsData_x = consumptionCharacteristicsData_x[:index + 1] + \
                                                   consumptionCharacteristicsData_x[
                                                   index + count_consumptionCharacteristicsData_y:]
                consumptionCharacteristicsData_commodity[index] = \
                    ",".join(
                        consumptionCharacteristicsData_commodity[index:index + count_consumptionCharacteristicsData_y])
                consumptionCharacteristicsData_commodity \
                    = consumptionCharacteristicsData_commodity[:index + 1] + \
                      consumptionCharacteristicsData_commodity[index + count_consumptionCharacteristicsData_y:]

    consumptionCharacteristicsData_xx = \
        [list(z) for z in zip(consumptionCharacteristicsData_x, consumptionCharacteristicsData_commodity)]

    scatter = Scatter(init_opts=opts.InitOpts(width="850px", height="380px"))
    scatter.add_xaxis(consumptionCharacteristicsData_y)
    scatter.add_yaxis("", consumptionCharacteristicsData_xx, color="red")
    scatter.set_global_opts(
        tooltip_opts=opts.TooltipOpts(
            trigger="item",
            axis_pointer_type="cross",
            formatter=JsCode(
                "function (params) {return '消费日期:' + params.name + ' <br/>消费金额:' + params.value[1] + '元 <br/>消费产品:' + params.value[2];}"
            )),
        yaxis_opts=opts.AxisOpts(
            name="消费金额",
            type_="value",
            name_textstyle_opts=opts.TextStyleOpts(color="white"),  ###########
            axislabel_opts=opts.LabelOpts(formatter="{value} 元",
                                          border_color="white",
                                          color="white"),  ########
            axistick_opts=opts.AxisTickOpts(is_show=True),
            splitline_opts=opts.SplitLineOpts(is_show=True),
        ),
        xaxis_opts=opts.AxisOpts(
            name="消费日期",
            type_="category",
            name_textstyle_opts=opts.TextStyleOpts(color="white"),  ###########
            axislabel_opts=opts.LabelOpts(border_color="white",
                                          color="white"),  ##############
            axispointer_opts=opts.AxisPointerOpts(is_show=True,
                                                  type_="shadow"),
        ),
        legend_opts=opts.LegendOpts(is_show=False))
    scatter.set_series_opts(label_opts=opts.LabelOpts(is_show=False))

    line = Line(init_opts=opts.InitOpts(width="850px", height="380px"))
    line.add_xaxis(consumptionCharacteristicsData_y)
    line.add_yaxis(series_name="",
                   y_axis=consumptionCharacteristicsData_x,
                   color="red")

    scatter.overlap(line)
    scatter.render("./static/html/pictureConsumptionCharacteristics.html")
    """互联网行为图"""
    internetBehaviorInfoKeys = list(internetBehaviorInfo.keys())
    internetBehaviorInfoKeys = list(
        map(lambda x: x.decode(), internetBehaviorInfoKeys))
    internetBehaviorInfoKeys = list(
        map(lambda x: x[:x.index(':')], internetBehaviorInfoKeys))
    internetBehaviorInfoValues = list(internetBehaviorInfo.values())
    internetBehaviorInfoValues = list(
        map(lambda x: x.decode(), internetBehaviorInfoValues))
    internetBehaviorInfoValues = list(map(int, internetBehaviorInfoValues))

    internetBehaviorData = []
    splitNum = int(len(internetBehaviorInfoValues) / 7)
    internetBehaviorData.append(internetBehaviorInfoValues[:splitNum])
    internetBehaviorData.append(internetBehaviorInfoValues[splitNum:2 *
                                                           splitNum])
    internetBehaviorData.append(internetBehaviorInfoValues[2 * splitNum:3 *
                                                           splitNum])
    internetBehaviorData.append(internetBehaviorInfoValues[3 * splitNum:4 *
                                                           splitNum])
    internetBehaviorData.append(internetBehaviorInfoValues[4 * splitNum:5 *
                                                           splitNum])
    internetBehaviorData.append(internetBehaviorInfoValues[5 * splitNum:6 *
                                                           splitNum])
    internetBehaviorData.append(internetBehaviorInfoValues[6 * splitNum:7 *
                                                           splitNum])

    internetBehaviorData = pd.DataFrame(internetBehaviorData).T
    internetBehaviorData.columns = [
        internetBehaviorInfoKeys[0], internetBehaviorInfoKeys[splitNum],
        internetBehaviorInfoKeys[2 * splitNum],
        internetBehaviorInfoKeys[3 * splitNum],
        internetBehaviorInfoKeys[4 * splitNum],
        internetBehaviorInfoKeys[5 * splitNum],
        internetBehaviorInfoKeys[6 * splitNum]
    ]

    internetBehaviorData.sort_values(by="date", inplace=True)
    internetBehaviorData_y = internetBehaviorData.loc[:, "date"].tolist()
    internetBehaviorData_y = list(map(str, internetBehaviorData_y))

    bar = Bar(init_opts=opts.InitOpts(width="800px", height="380px"))
    bar.add_xaxis(internetBehaviorData_y)
    bar.add_yaxis(series_name="新闻资讯",
                  yaxis_data=internetBehaviorData.loc[:, "news"].tolist(),
                  stack="stack")
    bar.add_yaxis(
        series_name="通信交流",
        yaxis_data=internetBehaviorData.loc[:, "communications"].tolist(),
        stack="stack")
    bar.add_yaxis(
        series_name="娱乐休闲",
        yaxis_data=internetBehaviorData.loc[:, "entertainment"].tolist(),
        stack="stack")
    bar.add_yaxis(
        series_name="生活服务",
        yaxis_data=internetBehaviorData.loc[:, "domersticServices"].tolist(),
        stack="stack")
    bar.add_yaxis(series_name="商务应用",
                  yaxis_data=internetBehaviorData.loc[:, "busApp"].tolist(),
                  stack="stack")
    bar.add_yaxis(series_name="工具使用",
                  yaxis_data=internetBehaviorData.loc[:, "toolUse"].tolist(),
                  stack="stack")
    bar.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    bar.set_global_opts(
        tooltip_opts=opts.TooltipOpts(is_show=True,
                                      trigger="axis",
                                      axis_pointer_type="cross"),
        xaxis_opts=opts.AxisOpts(
            name="日期",
            name_textstyle_opts=opts.TextStyleOpts(color="white"),  ###########
            type_="category",
            axislabel_opts=opts.LabelOpts(border_color="white",
                                          color="white"),  #############
            axispointer_opts=opts.AxisPointerOpts(is_show=True),
        ),
        yaxis_opts=opts.AxisOpts(
            name="时间",
            name_textstyle_opts=opts.TextStyleOpts(color="white"),
            type_="value",
            min_=0,
            max_=24,
            interval=4,
            axislabel_opts=opts.LabelOpts(formatter="{value} 小时",
                                          border_color="white",
                                          color="white"),  ###########
            axistick_opts=opts.AxisTickOpts(is_show=True),
        ),
        datazoom_opts=opts.DataZoomOpts(type_="inside"),
        legend_opts=opts.LegendOpts(is_show=True,
                                    textstyle_opts=opts.TextStyleOpts(
                                        border_color="white", color="wihte"),
                                    orient='horizontal'))
    bar.render("./static/html/pictureInternetBehavior.html")
    """个人特征图"""
    sValue = list(sInfo.values())
    sValue = list(map(lambda x: x.decode(), sValue))
    cValue = list(cInfo.values())
    cValue = list(map(lambda x: x.decode(), cValue))
    iValue = list(iInfo.values())
    iValue = list(map(lambda x: x.decode(), iValue))
    value = sValue + cValue + iValue
    value = list(map(int, value))

    value = [value[1], value[2], value[3], value[0], value[4]]
    value = [value]

    rader = Radar(init_opts=opts.InitOpts(width="350px", height="350px"))
    rader.add_schema(schema=[
        opts.RadarIndicatorItem(name="收入指数", max_=5),
        opts.RadarIndicatorItem(name="消费金\n额指数", max_=5),
        opts.RadarIndicatorItem(name="消费次数指数", max_=5),
        opts.RadarIndicatorItem(name="学历指数", max_=5),
        opts.RadarIndicatorItem(name="网络依\n赖指数", max_=5),
    ],
                     shape='polygon')
    rader.add(series_name=key_name, data=value)
    rader.set_global_opts(legend_opts=opts.LegendOpts(is_show=False))
    rader.render("./static/html/pictureCompositiveInfo.html")
コード例 #11
0
def find_difference_render(data,X,query,table_path,answer):
    colorList = ['#f36c6c', '#e6cf4e', '#20d180', '#0093ff',"#ca8622","#726930",]
    if len(data)==2:
        bar1=Bar()
        bar1.add_xaxis(X[1])
        bar1.add_yaxis("",data[0][1],label_opts=opts.LabelOpts(position="insideLeft"))
        bar1.reversal_axis()
        bar1.set_global_opts(
            datazoom_opts=[opts.DataZoomOpts(range_start=10,range_end=90,orient="vertical"), opts.DataZoomOpts(type_="inside")],
            xaxis_opts=opts.AxisOpts(
                position="top"
            ),
            yaxis_opts=opts.AxisOpts(
                is_inverse=True
            ),
            graphic_opts=[opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",

                ),
                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[1])
        bar2.add_yaxis("",data[1][1],label_opts=opts.LabelOpts(position="insideRight"))
        bar2.reversal_axis()
        bar2.set_global_opts(
            datazoom_opts=[opts.DataZoomOpts(range_start=10, range_end=90, orient="vertical"),
                           opts.DataZoomOpts(type_="inside")],
            xaxis_opts=opts.AxisOpts(
                position="top",
                is_inverse=True
            ),
            yaxis_opts=opts.AxisOpts(
                is_inverse=True,
                position="right"
            ),
            graphic_opts=[opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",

                ),
                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"
                    )
                )
            )]
        )
        grid1 = Grid(init_opts=opts.InitOpts(
            width="100%",
            height="100%",
            renderer=globals.RenderType.SVG, ) )
        grid1.add(bar1, grid_opts=opts.GridOpts(
            pos_left="60%",pos_bottom="30%"
        ))
        grid1.add(bar2, grid_opts=opts.GridOpts(
            pos_right="60%",pos_bottom="30%"
        ))
        grid1.render("a.html")
        option1 = grid1.dump_options_with_quotes()
        option1 = json.loads(option1)
        lable=[]
        for i in range(len(X[1])):
            lable.append(opts.RadarIndicatorItem(name=X[1][i]))
        # r_data=[]
        # for record in data:
        #     r_data.append(record[1])
        radar=Radar(init_opts=opts.InitOpts(bg_color="#CCCCCC"))
        radar.add_schema(
            schema=lable,
            splitarea_opt=opts.SplitAreaOpts(
               is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)
             ),
            textstyle_opts=opts.TextStyleOpts(color="#fff"),
        )
        for i in range(len(data)):
            radar.add(
                series_name=data[i][0],
                label_opts=opts.LabelOpts(is_show=False),
                data=[data[i][1]],
                linestyle_opts=opts.LineStyleOpts(
                    color=colorList[i],
                    width=3

                )
            )
        radar.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'+"\n" + 'A:' + ' ' + answer],
                    font="10px Microsoft YaHei",
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill="#333"
                    )
                )
            )]
        )
        grid2 = Grid(init_opts=opts.InitOpts(
            width="100%",
            height="100%",
            renderer=globals.RenderType.SVG, ))
        grid2.add(radar, grid_opts={'left': '20%', 'bottom': '40%',"top":"1%"})
        option2 = grid2.dump_options_with_quotes()
        option2 = json.loads(option2)
        bar3=Bar()
        bar3.add_xaxis(X[1])
        for i in range(len(data)):
            bar3.add_yaxis(data[i][0],data[i][1],label_opts=opts.LabelOpts(is_show=False))
        bar3.set_global_opts(
            datazoom_opts=[opts.DataZoomOpts(range_start=10, range_end=90),
                           opts.DataZoomOpts(type_="inside")],
            xaxis_opts=opts.AxisOpts(
                name=X[0]
            ),
            graphic_opts=[opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",
                ),
                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"
                    )
                )
            )]
        )
        grid3 = Grid(init_opts=opts.InitOpts(
            width="100%",
            height="100%",
            renderer=globals.RenderType.SVG, ))
        grid3.add(bar3, grid_opts={'left': '20%', 'bottom': '30%'})
        option3 = grid3.dump_options_with_quotes()
        option3 = json.loads(option3)
        option = {"option": [option1,option2,option3], "query": query}
        return option

    elif len(data)>2 and len(data[0][1])>1:
        lable=[]
        for i in range(len(X[1])):
            lable.append(opts.RadarIndicatorItem(name=X[1][i]))
        # r_data=[]
        # for record in data:
        #     r_data.append(record[1])
        radar=Radar(init_opts=opts.InitOpts(bg_color="#CCCCCC"))
        radar.add_schema(
            schema=lable,
            splitarea_opt=opts.SplitAreaOpts(
               is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)
             ),
            textstyle_opts=opts.TextStyleOpts(color="#fff"),
        )
        radar.set_global_opts(
            graphic_opts=[opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",

                ),
                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"
                    )
                )
            )]
        )
        for i in range(len(data)):
            radar.add(
                series_name=data[i][0],
                label_opts=opts.LabelOpts(is_show=False),
                data=[data[i][1]],
                linestyle_opts=opts.LineStyleOpts(
                    color=colorList[i],
                    width=3

                )
            )

        grid1 = Grid(init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer=globals.RenderType.SVG, ))
        grid1.add(radar, grid_opts={'left': '20%', 'bottom': '30%'})
        option1 = grid1.dump_options_with_quotes()
        option1 = json.loads(option1)
        bar = Bar()
        bar.add_xaxis(X[1])
        for i in range(len(data)):
          bar.add_yaxis(data[i][0], data[i][1],label_opts=opts.LabelOpts(is_show=False))
        bar.set_global_opts(
            datazoom_opts=[opts.DataZoomOpts(range_start=10, range_end=90),
                           opts.DataZoomOpts(type_="inside")],
          xaxis_opts=opts.AxisOpts(
            name=X[0]
          ),
            graphic_opts=[opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",

                ),
                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"
                    )
                )
            )]
        )
        grid2 = Grid(init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer=globals.RenderType.SVG, ))
        grid2.add(bar, grid_opts={'left': '20%', 'bottom': '30%'})
        option2 = grid2.dump_options_with_quotes()
        option2 = json.loads(option2)
        option = {"option": [option1,option2], "query": query}
        return option
    elif len(data)>2 and len(data[0][1])==1:
        bar = Bar()
        bar.add_xaxis(X[1])
        for i in range(len(data)):
          bar.add_yaxis(data[i][0], data[i][1],label_opts=opts.LabelOpts(is_show=False))
        bar.set_global_opts(
            datazoom_opts=[opts.DataZoomOpts(range_start=10, range_end=90),
                           opts.DataZoomOpts(type_="inside")],
          xaxis_opts=opts.AxisOpts(
            name=X[0]
          ),
            graphic_opts=[opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",
                ),
                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"
                    )
                )
            )]
        )
        grid2 = Grid(init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer=globals.RenderType.SVG, ))
        grid2.add(bar, grid_opts={'left': '20%', 'bottom': '34%'})
        option2 = grid2.dump_options_with_quotes()
        option2 = json.loads(option2)
        option = {"option": [option2], "query": query}
        return option