Beispiel #1
0
def bars_show(bar_data):
    # 显示多个柱状图
    page = Page()
    for b in bar_data:
        bar = create_bar(b['x'], b['head'], b['data'], b['dict'])
        page.add(bar)
    page.render()
Beispiel #2
0
def create_geo_charts(data, title):
    '''地图'''
    page = Page()
    # 样式
    style = Style(title_color="#fff",
                  title_pos="center",
                  width=1200,
                  height=600,
                  background_color='#c4ccd3')
    # 创建地图模型
    chart = Geo(title, "", **style.init_style)
    # 数据 ['上海', '北京', '广州', '深圳', '苏州'] [5, 40, 10, 15, 5]
    attr, value = chart.cast(data)
    # 添加数据
    chart.add("",
              attr,
              value,
              maptype='china',
              is_visualmap=True,
              type="effectScatter",
              is_legend_show=False,
              geo_emphasis_color='c4ccd3',
              visual_text_color='#2f4554')

    page.add(chart)

    return page
Beispiel #3
0
def get_pic_html():
    data = get_data("logs.txt")
    #获取DataFrame的行数
    rows = data.shape[0]
    #获取DataFrame的列数
    columns = data.shape[1]
    #绘制多幅图在一个页面,实例Page
    page = Page()
    #两个相同类型的曲线图间隔的列数
    # division=get_division()
    division = (int(columns) / int(files_number))
    for index in range((division - 1) / 3):
        type = [i[3 * index + 1] for i in data.values]
        title = type[0]
        subtitle = type[11]
        if "Sensitivity" not in title:
            line_pic = Line(title, subtitle)
            for compare in range(files_number):
                #添加曲线的limit
                if OK_Limit == True:
                    limit_path = "./limit/%s" % (station + ".txt")
                    x_Upper, y_Upper, x_Lower, y_Lower = get_limit_data(
                        title, limit_path)
                    if x_Upper != None and y_Upper != None:
                        line_pic.add("Upper Limit",
                                     x_Upper,
                                     y_Upper,
                                     is_legend_show=False)
                    if x_Lower != None and y_Lower != None:
                        line_pic.add("Lower Limit",
                                     x_Lower,
                                     y_Lower,
                                     is_legend_show=False)

                x = [
                    i[3 * index + 2 + compare * division] for i in data.values
                ]
                while 'NaN' in x:
                    x.remove('NaN')
                y = [
                    i[3 * index + 3 + compare * division] for i in data.values
                ]
                while 'NaN' in y:
                    y.remove('NaN')
                if int(float(x[0])) > int(float(x[1])):
                    x.reverse()
                    y.reverse()
                sn_info = [i[compare * division] for i in data.values][0]
                #print sn_info,x,y
                #line_pic=Line(title,subtitle)
                line_pic.add(sn_info,
                             x,
                             y,
                             is_smooth=True,
                             is_legend_show=False,
                             is_more_utils=True)
            page.add(line_pic)
    page.render('log.html')
    print u"Log图完成绘制,并生成log.html文件,请用浏览器打开"
    print u"Tips:每幅图都可以查看每条曲线的SN并进行图片下载"
Beispiel #4
0
def create_charts():
    page = Page()
    style = Style(width=WIDTH, height=HEIGHT)
    df = pd.read_csv('./data_cleaned.csv')
    table6 = pd.pivot_table(df,
                            values=['DISPOSE_UNIT_NAME'],
                            index=['INTIME_ARCHIVE_NUM'],
                            columns=['EVENT_TYPE_NAME'],
                            aggfunc='count',
                            fill_value=0)
    table6_2 = table6 / table6.sum()
    name = [i[1] for i in table6_2]
    value = [float(table6_2.values[0][j]) for j in range(len(name))]
    chart = Bar("超时结案", **style.init_style)
    chart.add("",
              name,
              value,
              is_datazoom_show=True,
              mark_line=["average"],
              is_stack=True,
              datazoom_type='both',
              datazoom_range=[10, 60])
    page.add(chart)

    return page
Beispiel #5
0
def create_two_bars():
    page = Page()

    # bar
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    bar = Bar("柱状图数据堆叠示例")
    bar.add("商家A", attr, v1, is_stack=True)
    bar.add("商家B", attr, v2, is_stack=True)
    page.add(bar)

    # scatter3D
    import random
    data = [[
        random.randint(0, 100),
        random.randint(0, 100),
        random.randint(0, 100)
    ] for _ in range(80)]
    range_color = [
        '#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf',
        '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026'
    ]
    scatter3D = Scatter3D("3D 散点图示例", width=1200, height=600)
    scatter3D.add("", data, is_visualmap=True, visual_range_color=range_color)
    page.add(scatter3D)
    return page
def create_combine_charts(dataframe):
    page = Page()
    # df= get_df_fromSQL('ori_data')
    df_new = pd.DataFrame()
    list1 = coltype_filter(dataframe, '套餐类型')
    num = len(list1)
    v1 = [x for x in range(0, num)]
    v2 = [x for x in range(0, num)]
    v3 = [x for x in range(0, num)]
    v4 = [x for x in range(0, num)]
    for i in range(0, num):
        df_new = detailed_info_filter(dataframe, '套餐类型', [list1[i]])
        v1[i] = month_Chuzhang(df_new)
    for i in range(0, num):
        df_new = detailed_info_filter(dataframe, '套餐类型', [list1[i]])
        v2[i] = APRU_Chuzhang(df_new)
    # for i in range(0,num):
    # 	df=dataframe[dataframe['套餐类型']==list1[i]]
    # 	v3[i]=MOU(df)
    # for i in range(0,num):
    # 	df = dataframe[dataframe['套餐类型']==list1[i]]
    # 	v4[i]=DOU(df)
    chart = Bar("数据分析", '总收入/平均出帐收入/MOU/DOU')
    chart.add('总收入', list, v1)
    chart.add("月平均收入", list, v2)
    # chart.add('MOU',list,v3)
    # chart.add('DOU',list,v4)
    page.add(chart)
    return page
Beispiel #7
0
def brush(data):
    data = hist_sum(data)
    kline = Kline()
    kline.add(
        'Kline',
        data.index,
        data.loc[:, ['open', 'close', 'low', 'high']].values,
        mark_line=['max', 'min'],
        mark_line_valuedim=['highest', 'lowest'],
        is_datazoom_show=True,
        datazoom_xaxis_index=[0, 1],
    )
    brush = Line()
    brush.add(
        'Brush',
        data.index,
        data.endpoint.values,
    )
    overlap = Overlap()
    overlap.add(kline)
    overlap.add(brush)

    macd = Bar()
    macd.add(
        'MACD',
        data.index,
        data.hist_sum.values,
    )
    page = Page()
    page.add(overlap)
    page.add(macd)
    return page
Beispiel #8
0
def genReport2(date):

    DB = DBfunction.getDB()

    ListU = DBfunction.getUserlist(DB)

    for i in range(0, len(ListU)):
        User = ListU[i]
        ListS = DBfunction.getUserStock(DB, User)
        ListM = DBfunction.getUserMethod(DB, User)

        page = Page()

        l1 = Reporter.plotKline('sh')
        l3 = Reporter.plotKline('hs300')
        page.add_chart(l1, name='the 200 day Kline of SH ')
        page.add_chart(l3, name='the 200 day Kline of HS300')

        for i in range(0, len(ListS)):
            Symbol = ListS[i]
            l1 = Reporter.plotKline(Symbol)
            page.add_chart(l1, name='the 200 day Kline of ' + Symbol)

            for j in range(0, len(ListM)):
                stg = ListM[j]
                exec('l = Reporter.plot2{}(Symbol)'.format(stg))
                exec('page.add_chart(l)')

        page.render('./report/' + User + '.html')
        page.render('./hist/' + User + ' ' + date + '.html')
Beispiel #9
0
def create_charts():
    page = Page()

    style = Style(
        width=WIDTH, height=HEIGHT
    )
    _data = []
    for t in range(0, 25000):
        _t = t / 1000
        x = (1 + 0.25 * math.cos(75 * _t)) * math.cos(_t)
        y = (1 + 0.25 * math.cos(75 * _t)) * math.sin(_t)
        z = _t + 2.0 * math.sin(75 * _t)
        _data.append([x, y, z])
    chart = Line3D("3D 折线图-默认", **style.init_style)
    chart.add("", _data, is_visualmap=True, visual_range_color=RANGE_COLOR,
              visual_range=[0, 30], grid3d_rotate_sensitivity=5)
    page.add(chart)

    _data = []
    for t in range(0, 25000):
        _t = t / 1000
        x = (1 + 0.25 * math.cos(75 * _t)) * math.cos(_t)
        y = (1 + 0.25 * math.cos(75 * _t)) * math.sin(_t)
        z = _t + 2.0 * math.sin(75 * _t)
        _data.append([x, y, z])
    chart = Line3D("3D 折线图-自动旋转", **style.init_style)
    chart.add("", _data, is_visualmap=True, visual_range_color=RANGE_COLOR,
              visual_range=[0, 30], is_grid3d_rotate=True,
              grid3d_rotate_speed=180)
    page.add(chart)

    return page
Beispiel #10
0
def create_three():
    page = Page()

    # bar
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    bar = Bar("柱状图数据堆叠示例")
    bar.add("商家A", attr, v1, is_stack=True)
    bar.add("商家B", attr, v2, is_stack=True)
    page.add(bar)

    # scatter3D
    import random
    data = [
        [random.randint(0, 100), random.randint(0, 100), random.randint(0, 100)] for _ in range(80)
    ]
    range_color = ['#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf',
                   '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026']
    scatter3d = Scatter3D("3D 散点图示例", width=1200, height=600)
    scatter3d.add("", data, is_visualmap=True, visual_range_color=range_color)
    page.add(scatter3d)

    # guangdong
    value = [20, 190, 253, 77, 65]
    attr = ['汕头市', '汕尾市', '揭阳市', '阳江市', '肇庆市']
    map = Map("广东地图示例", width=1200, height=600)
    map.add("", attr, value, maptype='广东', is_visualmap=True,
            visual_text_color='#000')
    page.add(map)

    return page
Beispiel #11
0
def main():
    '''
    # 测试词云图
    x = [
        "python", "lxj", "zj", "big data", "python", "lxj", "zj", "big data",
        "python", "lxj", "zj", "big data", "python", "lxj", "zj", "big data"
        ]
    y = [
        10000, 8000, 6000, 3000, 10000, 8000, 6000, 3000,
        10000, 8000, 6000, 3000, 10000, 8000, 6000, 3000
        ]
    label = "词云"
    wordCloud(x, y, label)
    '''
    '''
    # 测试统计图表    
    x = ["衬衫", "袜子", "高跟鞋", "羊毛衫", "裤子"]
    y1 = [5, 10, 38, 75, 90]
    y2 = [15, 4, 70, 25, 190]
    label = "服装"
    type = 2
    get_charts(x, y, label, type)
    '''
    '''
    # 测试多个统计图
    page = Page()
    get_otherCharts(page)
    '''

    # 测试三维散点图
    page = Page()
    get_scatter3D(page)
def analysisProvince():
    friends_info = get_friends_info()
    df = pd.DataFrame(friends_info)
    province_count = df.groupby(
        'province', as_index=True)['province'].count().sort_values()
    print('province', province_count)
    print(list(province_count))
    temp = list(
        map(lambda x: x if x != '' else '未知', list(province_count.index)))
    print('temp', temp)
    # 画图
    page = Page()
    style = Style(width=1100, height=600)
    style_middle = Style(width=900, height=500)
    attr, value = temp, list(province_count)
    chart1 = Map('好友分布(中国地图)', **style.init_style)
    chart1.add('',
               attr,
               value,
               is_label_show=True,
               is_visualmap=True,
               visual_text_color='#000')
    page.add(chart1)
    chart2 = Bar('好友分布柱状图', **style_middle.init_style)
    chart2.add('',
               attr,
               value,
               is_stack=True,
               is_convert=True,
               label_pos='inside',
               is_legend_show=True,
               is_label_show=True)
    page.add(chart2)
    page.render('analysisProvince.html')
def analysisSex():
    friends_info = get_friends_info()
    print('friends_info', friends_info)
    df = pd.DataFrame(friends_info)
    df.to_excel('C:/Users/15432/Desktop/df.xlsx')
    sex_count = df.groupby(['sex'], as_index=True)['sex'].count()
    print('sex_count', type(sex_count), sex_count)
    temp = dict(zip(list(sex_count.index), list(sex_count)))  # zip对俩个列表打包成元组
    print('temp', temp)
    data = {}
    data['保密'] = temp.pop(0)  # 取出字典给定键 key 所对应的值
    data['男'] = temp.pop(1)
    data['女'] = temp.pop(2)
    print('data', data)
    # 画图
    page = Page()
    attr, value = data.keys(), data.values()
    chart = Pie('微信好友性别比')
    chart.add('',
              attr,
              value,
              center=[50, 50],
              redius=[30, 70],
              is_label_show=True,
              legend_orient='horizontal',
              legend_pos='center',
              legend_top='bottom',
              is_area_show=True)
    page.add(chart)
    page.render('analysisSex.html')
Beispiel #14
0
def liquid_charts():
    page = Page()

    chart_init = {
        "width": WIDTH,
        "height": HEIGHT,
    }

    chart = Liquid("水球图-单数据", **chart_init)
    chart.add("Liquid", [0.6])
    page.add(chart)

    chart = Liquid("水球图-多数据", **chart_init)
    chart.add("Liquid", [0.6, 0.5, 0.4, 0.3], is_liquid_outline_show=False)
    page.add(chart)

    chart = Liquid("水球图-圆角", **chart_init)
    chart.add("Liquid", [0.6, 0.5, 0.4, 0.3],
              is_liquid_outline_show=False,
              shape='roundRect')
    page.add(chart)

    chart = Liquid("水球图-箭头", **chart_init)
    chart.add("Liquid", [0.6, 0.5, 0.4, 0.3],
              is_liquid_outline_show=False,
              shape='arrow')
    page.add(chart)

    chart = Liquid("水球图-动画静止", **chart_init)
    chart.add("Liquid", [0.6, 0.5, 0.4, 0.3],
              is_liquid_animation=False,
              shape='diamond')
    page.add(chart)

    return page
def make_plot(city):
    city_dict = make_city_dict()
    # 倒入包
    data = pd.read_csv('csv_files/%s/groupby_region_df.csv'%city)
    # 读取数据

    configure(global_theme='vintage')
    # 设置主题

    X_axis = data["地区"].tolist()
    v1 = data["每平方米单价(单位:元)"].tolist()
    v2 = data["总价(单位:万元)"].tolist()
    bar1 = Bar(title="%s各区域二手房单价分布条形图"%city_dict[city], width=1500, height=600)
    bar1.add("单价",
             X_axis,
             v1,
             mark_point=["max", "min"],
             mark_line=['average'],
             mark_point_textcolor='#000',
             xaxis_rotate=45,
             mark_point_symbol="pin", )
    bar2 = Bar(title="%s各区域二手房总价分布条形图"%city_dict[city], width=1500, height=600)
    bar2 = bar2.add("总价",
                    X_axis,
                    v2,
                    mark_point=["max", "min"],
                    mark_line=['average'],
                    xaxis_rotate=45,
                    mark_point_textcolor='#000',
                    mark_point_symbol="pin", )
    page = Page()
    page.add_chart(bar1)
    page.add_chart(bar2)
    return page
Beispiel #16
0
    def draw_publisher_author_word_cloud(self, publisher: list, author: list):
        """
        画出版社和作者的词云
        :param publisher:
        :param author:
        :return: 无返回值(如果self._json_mode为True则有返回值)
        """
        if len(publisher) < 1:
            logger.error("No Data!")
            raise ValueError("Publisher list is empty!")
        elif len(author) < 1:
            logger.error("No Data!")
            raise ValueError("Author list is empty!")

        name = ['热门出版社', '热门作者']

        # 画图
        page = Page()
        chart = WordCloud(name[0], **self.style.init_style)
        chart.add("", publisher[0], publisher[1], word_size_range=[12, 80], shape="cardioid")
        page.add(chart)

        chart_1 = WordCloud(name[1], **self.style.init_style)
        chart_1.add("", author[0], author[1], word_size_range=[12, 80], shape="pentagon")
        page.add(chart_1)

        if self._json_mode:
            chart_json = [chart.options, chart_1.options]
            return chart_json
        else:
            logger.debug("正在导出: " + Echart_Output_Path + "&".join(name) + ".html")
            page.render(Echart_Output_Path + "&".join(name) + ".html")
def create_total_charts(df):
    page = Page()
    df_new = pd.DataFrame()
    list1 = coltype_filter(df, '套餐类型')
    num = len(list1)
    v1 = [x for x in range(0, num)]
    for i in range(0, num):
        df_new = df[df['套餐类型'] == list1[i]]
        v1[i] = month_Chuzhang(df_new)
    # v2 = [10, 25, 8, 60, 20, 80]
    v2 = [x for x in range(0, num)]
    for i in range(0, num):
        df_new = df[df['套餐类型'] == list1[i]]
        v2[i] = APRU_Chuzhang(df_new)
    v3 = [x for x in range(0, num)]
    for i in range(0, num):
        df_new = df[df['套餐类型'] == list1[i]]
        v3[i] = MOU(df_new)
    v4 = [x for x in range(0, num)]
    for i in range(0, num):
        df_new = df[df['套餐类型'] == list1[i]]
        v4[i] = DOU(df_new)
    chart = Bar("数据分析", "月总收入/平均收入/MOU/DOU")
    chart.add("月总收入", list1, v1)
    chart.add("各套餐平均收入", list1, v2)
    chart.add("MOU", list1, v3)
    chart.add("DOU", list1, v4)
    # chart.add("月平均收入", attr, v2, is_stack=True, is_more_utils=True)
    page.add(chart)
    return page
Beispiel #18
0
    def draw_book_price_chart(self, stage_list: list):
        """
        图书价格分布图
        :param stage_list: 各分段数据
        :return:
        """
        page = Page()
        x = ["0~20", "20~40", "40~60", "60~80", "80~100", "100~"]
        bar_chart = Bar("图书价格分布(柱状图)", **self.style.init_style)
        bar_chart.add("", x, stage_list, is_more_utils=True, is_label_show=True)
        page.add(bar_chart)

        pie_chart = Pie("图书价格分布(饼图)", **self.style.init_style)
        pie_chart.add("", x, stage_list,
                      is_label_show=True,
                      legend_orient='vertical',
                      legend_pos='left',
                      legend_top="center")
        page.add(pie_chart)

        if self._json_mode:
            chart_json = [bar_chart.options, pie_chart.options]
            return chart_json
        else:
            logger.debug("正在导出: " + Echart_Output_Path + "图书价格分布图" + ".html")
            page.render(Echart_Output_Path + "图书价格分布图" + ".html")
Beispiel #19
0
def create_three():
    page = Page(page_title=TEST_PAGE_TITLE)

    # bar
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    bar = Bar("柱状图数据堆叠示例")
    bar.add("商家A", CLOTHES, v1, is_stack=True)
    bar.add("商家B", CLOTHES, v2, is_stack=True)
    page.add(bar)

    # scatter3D
    import random
    data = [[
        random.randint(0, 100),
        random.randint(0, 100),
        random.randint(0, 100)
    ] for _ in range(80)]
    scatter3d = Scatter3D("3D 散点图示例", width=1200, height=600)
    scatter3d.add("", data, is_visualmap=True, visual_range_color=RANGE_COLOR)
    page.add(scatter3d)

    # guangdong
    value = [20, 190, 253, 77, 65]
    attr = ['汕头市', '汕尾市', '揭阳市', '阳江市', '肇庆市']
    map = Map("广东地图示例", width=1200, height=600)
    map.add("",
            attr,
            value,
            maptype='广东',
            is_visualmap=True,
            visual_text_color='#000')
    page.add(map)

    return page
def create_charts():
    page = Page()

    attr = ["男性", "女性", "无性别"]
    gender = [12773970, 6479097, 797077]
    chart = Pie("性别", title_pos='center')
    chart.add("", attr, gender, is_label_show=True)
    page.add(chart)

    attr = ["50后", "60后", "70后", "80后", "90后", "其他"]
    age = [971253, 2758022, 5078234, 7395064, 1514256, 945754]
    chart = Bar("性别", title_pos='center')
    chart.add("", attr, age, is_stack=True)
    page.add(chart)

    attr = [
        "@qq.com", " @163.com", "@126.com", "@hotmail.com", "@sina.com",
        "@yahoo.com.cn", "@gmail.com", "@139.com", "@sohu.com", "@yahoo.cn"
    ]
    email = [
        611842, 594392, 274512, 203237, 151798, 101692, 96346, 67565, 50179,
        31274
    ]
    chart = Pie("Top10 邮箱域名", title_pos='center')
    chart.add("",
              attr,
              email,
              is_random=True,
              radius=[20, 80],
              rosetype='radius',
              legend_orient='vertical',
              legend_pos='left')
    page.add(chart)
    return page
Beispiel #21
0
def creat_lan_charts(data_list):
    page = Page()
    style = Style(title_color="#fff",
                  title_pos="center",
                  width=1200,
                  height=600,
                  background_color='#404a59')

    chart = Geo("python", "python-city", **style.init_style)
    attr, value = chart.cast(data_list)
    chart.add("",
              attr,
              value,
              visual_range=[0, 200],
              visual_text_color="#fff",
              is_legend_show=False,
              symbol_size=15,
              is_visualmap=True,
              tooltip_formatter='{b}',
              label_emphasis_textsize=15,
              label_emphasis_pos='right')
    page.add(chart)

    chart = Geo("全国主要城市空气质量", "data from pm2.5", **style.init_style)
    attr, value = chart.cast(data_list)
    chart.add("",
              attr,
              value,
              type="heatmap",
              is_visualmap=True,
              visual_range=[0, 200],
              visual_text_color='#fff',
              is_legend_show=False)
    page.add(chart)
    return page
Beispiel #22
0
def huati(name,num,k):#看各级的销量
    kk=[]
    for i in range(len(name)):
        if not numpy.isnan(num[i]):
            q = []
            q.append(name[i])
            q.append(num[i])
            # q[name[i]]=hot[i]
            kk.append(q)
    hh=sorted(kk,key=lambda i:i[1],reverse=True)
    page=Page()
    att,val=[],[]
    for i in hh[:20]:
        att.append(i[0])
        val.append(i[1])
    bar1 = Bar("", k+"A景区销量排行", title_pos="center", width=1200, height=600)
    bar1.add("",att,val, is_visualmap=True, visual_text_color='#fff', mark_point=["average"],
            mark_line=["average"],
            is_more_utils=True, is_label_show=True, is_datazoom_show=True, xaxis_rotate=45)
    page.add_chart(bar1)
    att, val = [], []
    for i in hh[-20:]:
        att.append(i[0])
        val.append(i[1])
    bar2 = Bar("", k+"A景区销量排行", title_pos="center", width=1200, height=600)
    bar2.add("", att, val, is_visualmap=True, visual_text_color='#fff', mark_point=["average"],
             mark_line=["average"],
             is_more_utils=True, is_label_show=True, is_datazoom_show=True, xaxis_rotate=45)
    page.add_chart(bar2)
    page.render(k+"A景区销量bar.html")
Beispiel #23
0
def create_charts():
    page = Page()
    conn=mysql2pd('140.143.161.111', '3306', 'mm', 'root', 'a091211')
    data=conn.doget("select 监测点,AQI指数,`PM2.5`,PM10,Co,No2,So2,O3,updata_time from aqi")
    conn.close()
    ps=data['监测点'].drop_duplicates().values
    ts=data['updata_time'].drop_duplicates().values
    cs=['AQI指数','PM2.5','PM10','Co','No2','So2','O3']
    for p in ps:
        res = []
        data1=data[data['监测点']==p]
        for i,c in enumerate(cs):
            for x,t in enumerate(ts):
                data2=data1[data1['updata_time']==t]
                for l in list(data2[c].values):
                    res.append([i,x,l])
        style = Style(
            width=WIDTH, height=HEIGHT
        )
        chart = Bar3D(p, **style.init_style)
        chart.add(p, ts, cs, [{'name':ts[d[1]],'value':[d[1], d[0], d[2]]} for d in res],
                  is_visualmap=True, visual_range=[0, 180],
                  visual_range_color=RANGE_COLOR,
                  grid3d_width=80, grid3d_depth=80)
        page.add(chart)
    return page
Beispiel #24
0
def gen_zwyx_dd(zwlb):
    qs = ZpZwByAreaModel.objects
    if zwlb:
        qs = qs.filter(zwlb=zwlb)
        path = f'zwyx_dd/{zwlb}.html'
    else:
        path = 'zwyx_dd.html'
    page = Page()
    df = read_frame(qs.all())
    if len(df) > 0:
        df_group = df.groupby(['year', 'month'])
        time_line_chart1 = Timeline(width=1500,
                                    height=450,
                                    is_auto_play=False,
                                    timeline_bottom=0)
        time_line_chart2 = Timeline(width=1500,
                                    height=450,
                                    is_auto_play=False,
                                    timeline_bottom=0)
        for name, group in df_group:
            # 地图 平均薪资
            month = group['month'].tolist()[0]
            year = group['year'].tolist()[0]
            df_new = group.groupby('province').apply(
                get_echarts_all_by_zwyx_value, 'province')
            data = [
                (a, (b + c) / 2)
                for a, b, c in zip(df_new['province'].tolist(
                ), df_new['max_zwyx'].tolist(), df_new['min_zwyx'].tolist())
            ]
            chart = Map(f'{zwlb}平均职位月薪与地点', width=1500, height=450)
            attr, value = chart.cast(data)
            chart.add(f'平均薪资',
                      attr,
                      value,
                      wmaptype='china',
                      is_label_show=True,
                      is_visualmap=True,
                      visual_range=[int(min(value)),
                                    int(max(value))],
                      visual_pos='right',
                      visual_top='top')
            time_line_chart1.add(chart, f'{year}年{month}月')

            # 本月职位量Top20
            chart3 = Pie(f'{zwlb}职位量及招聘人数', width=1500)
            chart3.add('职位量',
                       df_new['province'].tolist(),
                       df_new['count'].tolist(),
                       center=[25, 50],
                       is_label_show=True)
            chart3.add('招聘人数',
                       df_new['province'].tolist(),
                       df_new['zprs'].tolist(),
                       center=[75, 50],
                       is_label_show=True)
            time_line_chart2.add(chart3, f'{year}年{month}月')
        page.add(time_line_chart1)
        page.add(time_line_chart2)
        page.render(os.path.join(BASE_DIR, 'templates/{}'.format(path)))
Beispiel #25
0
def drawKline(datadf, tradeRecorddf):
    datadf["datetime"] = datadf["datetime"].dt.strftime("%Y-%m-%d %H:%M:%S")
    OHLC = df[["open", "close", "low", "high"]]
    OHLC = OHLC.values
    DATETIME = df["datetime"].values

    longOrderDF = tradeRecorddf[tradeRecorddf["direction"] == "long position"]
    longOrderDF = longOrderDF[["time", "deal price", "kaiping"]].values
    shortOrderDF = tradeRecorddf[tradeRecorddf["direction"] == "short position"]
    shortOrderDF = shortOrderDF[["time", "deal price", "kaiping"]].values
    markpointlist = []
    for longorders in longOrderDF:
        markpointlist.append(RedArrow(longorders[0], longorders[1], longorders[2]))
    for shortorders in shortOrderDF:
        markpointlist.append(GreenArrow(shortorders[0], shortorders[1], shortorders[2]))

    page = Page()
    grid = Grid(width=1920, height=900)
    kline = Kline("candlestick")
    kline.add("candlestick", DATETIME, OHLC, is_datazoom_show=True, datazoom_type='inside',
              datazoom_range=[90, 100], tooltip_tragger_on='mousemove|click', tooltip_axispointer_type='cross',
              is_label_show=False, mark_point_raw=markpointlist)
    grid.add(kline, grid_top="3%", grid_height="95%")
    page.add(grid)
    now = dt.datetime.now()
    today = now.strftime('%Y%m%d')
    time = now.strftime("%H_%M_%S")
    home = os.environ['HOME']
    page.render(home + "/Pictures/" + today + "/" + "plotKlineChartandSignal" + time + ".html")
Beispiel #26
0
def gen_zwyx_type(zwlb):
    qs = ZpZwyxByTypeModel.objects
    if zwlb:
        qs = qs.filter(zwlb=zwlb)
        path = f'zwyx_type/{zwlb}.html'
    else:
        path = 'zwyx_type.html'
    # 当月职位月薪与公司性质
    df = read_frame(qs.all())
    if len(df) > 0:
        page = Page()
        Grid_chart1 = Timeline(width=1500, height=450, timeline_bottom=0)
        Grid_chart2 = Timeline(width=1500, height=450, timeline_bottom=0)
        df_group = df.groupby(['year', 'month'])
        for name, group in df_group:
            month = group['month'].tolist()[0]
            year = group['year'].tolist()[0]
            df_new = group.groupby('type').apply(get_echarts_all_by_zwyx_value,
                                                 'type')
            # 薪资
            Overlap_chart = Overlap(width=800, height=450)
            bar_chart = Bar(f'{zwlb}职位月薪与公司性质')
            bar_chart.add('最低薪资',
                          df_new['type'].tolist(),
                          df_new['min_zwyx'].tolist(),
                          is_label_show=True,
                          is_more_utils=True)
            bar_chart.add('最高薪资',
                          df_new['type'].tolist(),
                          df_new['max_zwyx'].tolist(),
                          is_label_show=True,
                          is_more_utils=True)
            line_chart = Line()
            line_chart.add("平均薪资",
                           df_new['type'].tolist(),
                           [(a + b) / 2
                            for a, b in zip(df_new['min_zwyx'].tolist(),
                                            df_new['max_zwyx'].tolist())],
                           is_label_show=True)
            Overlap_chart.add(bar_chart)
            Overlap_chart.add(line_chart)
            Grid_chart1.add(Overlap_chart, f'{year}年{month}月')
            # 职位量
            chart3 = Pie(f'{zwlb}职位量及招聘人数', width=1500)
            chart3.add('职位量'.format(zwlb),
                       df_new['type'].tolist(),
                       df_new['count'].tolist(),
                       is_label_show=True,
                       is_stack=True,
                       center=[25, 50])
            chart3.add('招聘人数'.format(zwlb),
                       df_new['type'].tolist(),
                       df_new['zprs'].tolist(),
                       is_label_show=True,
                       is_stack=True,
                       center=[75, 50])
            Grid_chart2.add(chart3, f'{year}年{month}月')
        page.add(Grid_chart1)
        page.add(Grid_chart2)
        page.render(os.path.join(BASE_DIR, 'templates/{}'.format(path)))
Beispiel #27
0
def create_charts():
    page = Page()

    chart_init = {
        "width": WIDTH,
        "height": HEIGHT,
    }

    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    value = [20, 40, 60, 80, 100, 120]
    chart = Funnel("漏斗图示例", **chart_init)
    chart.add("商品",
              attr,
              value,
              is_label_show=True,
              label_pos="inside",
              label_text_color="#fff")
    page.add(chart)

    chart = Funnel("漏斗图示例", title_pos='center', **chart_init)
    chart.add("商品",
              attr,
              value,
              is_label_show=True,
              label_pos="outside",
              legend_orient='vertical',
              legend_pos='left')
    page.add(chart)

    return page
Beispiel #28
0
def gen_gwzz_word(zwlb):
    qs = ZpWordByZwlbModel.objects
    if zwlb:
        qs = qs.filter(zwlb=zwlb)
        path = f'zp_word/{zwlb}.html'
    else:
        path = 'zp_word.html'
    df = read_frame(qs.all())
    if len(df) > 0:
        page = Page()
        Grid_chart1 = Timeline(width=1500, height=800, timeline_bottom=0)
        df_group = df.groupby(['year', 'month'])
        for name, group in df_group:
            month = group['month'].tolist()[0]
            year = group['year'].tolist()[0]
            df_new = group.groupby('word').apply(get_echarts_all_by_value,
                                                 'word')
            chart = WordCloud(f'{zwlb}岗位需求词云', width=1500)
            shape_list = [
                None, 'circle', 'cardioid', 'diamond', 'triangle-forward',
                'triangle', 'pentagon', 'star'
            ]
            chart.add("",
                      df_new['word'].tolist(),
                      df_new['count'].tolist(),
                      word_size_range=[30, 100],
                      rotate_step=66,
                      shape=shape_list[random.randint(0,
                                                      len(shape_list) - 1)])
            Grid_chart1.add(chart, f'{year}年{month}月')
        page.add(Grid_chart1)
        page.render(os.path.join(BASE_DIR, 'templates/{}'.format(path)))
Beispiel #29
0
def create_charts():
    page = Page()

    style = Style(
        width=1100, height=600
    )

    name = [
        'Sam S Club', 'Macys', 'Amy Schumer', 'Jurassic World',
        'Charter Communications', 'Chick Fil A', 'Planet Fitness',
        'Pitch Perfect', 'Express', 'Home', 'Johnny Depp', 'Lena Dunham',
        'Lewis Hamilton', 'KXAN', 'Mary Ellen Mark', 'Farrah Abraham',
        'Rita Ora', 'Serena Williams', 'NCAA baseball tournament', 'Point Break']
    value = [
        10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112,
        965, 847, 582, 555, 550, 462, 366, 360, 282, 273, 265]
    chart = WordCloud("词云图-默认形状", **style.init_style)
    chart.add("", name, value, word_size_range=[30, 100], rotate_step=66)
    page.add(chart)

    chart = WordCloud("词云图-自定义形状", **style.init_style)
    chart.add("", name, value, word_size_range=[30, 100], shape='diamond')
    page.add(chart)

    return page
Beispiel #30
0
def lines_show(line_data):
    # 显示多个曲线图
    page = Page()
    for b in line_data:
        line = create_line(b['x'], b['head'], b['data'], b['dict'])
        page.add(line)
    page.render()