def test_grid_2(): attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图示例", height=720, width=1200, title_pos="65%") bar.add("商家A", attr, v1, is_stack=True) bar.add("商家B", attr, v2, is_stack=True, legend_pos="80%") line = Line("折线图示例") attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] line.add("最高气温", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"]) line.add("最低气温", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"], legend_pos="20%") v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] scatter = Scatter("散点图示例", title_top="50%", title_pos="65%") scatter.add("scatter", v1, v2, legend_top="50%", legend_pos="80%") es = EffectScatter("动态散点图示例", title_top="50%") es.add("es", [11, 11, 15, 13, 12, 13, 10], [1, -2, 2, 5, 3, 2, 0], effect_scale=6, legend_top="50%", legend_pos="20%") grid = Grid() grid.add(bar, grid_bottom="60%", grid_left="60%") grid.add(line, grid_bottom="60%", grid_right="60%") grid.add(scatter, grid_top="60%", grid_left="60%") grid.add(es, grid_top="60%", grid_right="60%") grid.render()
def test_grid_four_direction(): v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图示例", height=720, width=1200, title_pos="65%") bar.add("商家A", CLOTHES, v1, is_stack=True) bar.add("商家B", CLOTHES, v2, is_stack=True, legend_pos="80%") line = Line("折线图示例") line.add("最高气温", WEEK, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"]) line.add("最低气温", WEEK, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"], legend_pos="20%") v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] scatter = Scatter("散点图示例", title_top="50%", title_pos="65%") scatter.add("scatter", v1, v2, legend_top="50%", legend_pos="80%") es = EffectScatter("动态散点图示例", title_top="50%") es.add("es", [11, 11, 15, 13, 12, 13, 10], [1, -2, 2, 5, 3, 2, 0], effect_scale=6, legend_top="50%", legend_pos="20%") grid = Grid() grid.add(bar, grid_bottom="60%", grid_left="60%") grid.add(line, grid_bottom="60%", grid_right="60%") grid.add(scatter, grid_top="60%", grid_left="60%") grid.add(es, grid_top="60%", grid_right="60%") grid.render()
def test_grid_inverse_yaxis(): attr = ['{}天'.format(i) for i in range(1, 31)] line_top = Line("折线图示例", width=1200, height=700) line_top.add( "最高气温", attr, [random.randint(20, 100) for i in range(30)], mark_point=["max", "min"], mark_line=["average"], legend_pos='38%', ) line_bottom = Line() line_bottom.add( "最低气温", attr, [random.randint(20, 100) for i in range(30)], mark_point=["max", "min"], mark_line=["average"], is_yaxis_inverse=True, xaxis_pos='top', ) grid = Grid() grid.add(line_top, grid_bottom='60%') grid.add(line_bottom, grid_top='50%') grid.render()
def test_grid_top_bottom(): v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图示例", height=720) bar.add("商家A", CLOTHES, v1, is_stack=True) bar.add("商家B", CLOTHES, v2, is_stack=True) line = Line("折线图示例", title_top="50%") line.add( "最高气温", WEEK, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"], ) line.add( "最低气温", WEEK, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"], legend_top="50%", ) grid = Grid() grid.add(bar, grid_bottom="60%") grid.add(line, grid_top="60%") grid.render()
def test_grid_add_overlap(): from pyecharts import Overlap grid = Grid() attr = ["{}月".format(i) for i in range(1, 13)] v1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3] v2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3] v3 = [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2] bar = Bar("Overlap+Grid 示例", width=1200, height=600, title_pos="40%") bar.add("蒸发量", attr, v1) bar.add( "降水量", attr, v2, yaxis_formatter=" ml", yaxis_max=250, legend_pos="85%", legend_orient="vertical", legend_top="45%", ) line = Line() line.add("平均温度", attr, v3, yaxis_formatter=" °C") overlap = Overlap() overlap.add(bar) overlap.add(line, is_add_yaxis=True, yaxis_index=1) grid.add(overlap, grid_right="20%") grid.render()
def test_grid_line_pie(): line = Line("折线图示例", width=1200) line.add( "最高气温", WEEK, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"], ) line.add( "最低气温", WEEK, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"], legend_pos="20%", ) v1 = [11, 12, 13, 10, 10, 10] pie = Pie("饼图示例", title_pos="55%") pie.add( "", CLOTHES, v1, radius=[45, 65], center=[65, 50], legend_pos="80%", legend_orient='vertical', ) grid = Grid() grid.add(line, grid_right="55%") grid.add(pie, grid_left="60%") grid.render()
def get_bar(item_name, subtitle, item_name_list, item_num_list): bar = Bar(item_name, page_title=item_name, title_text_size=30, title_pos='center', subtitle=subtitle, subtitle_text_size=25) bar.add("", item_name_list, item_num_list, title_pos='center', xaxis_interval=0, xaxis_rotate=27, xaxis_label_textsize=20, yaxis_label_textsize=20, yaxis_name_pos='end', yaxis_pos="%50") bar.show_config() grid = Grid(width=1300, height=800) grid.add(bar, grid_top="13%", grid_bottom="23%", grid_left="15%", grid_right="15%") out_file_name = './analyse/' + item_name + '.html' grid.render(out_file_name)
def visualize(): max10 = getMaxTop() min10 = getMinTop() max_cities = list(map(lambda x: x['city'], max10)) max_top = list(map(lambda x: x['max'], max10)) min_cities = list(map(lambda x: x['city'], min10)) min_top = list(map(lambda x: x['min'], min10)) bar_max = Bar('中国最高温排行榜') bar_max.add('', max_cities, max_top) bar_min = Bar('中国最低温排行榜', title_top="50%") bar_min.add('', min_cities, min_top) grid = Grid(height=720) grid.add(bar_max, grid_bottom="60%") grid.add(bar_min, grid_top="60%") grid.render('temperature.html') print(max10) print(min10)
def test_grid_inverse_yaxis(): attr = ["{}天".format(i) for i in range(1, 31)] line_top = Line("折线图示例", width=1200, height=700) line_top.add( "最高气温", attr, [random.randint(20, 100) for i in range(30)], mark_point=["max", "min"], mark_line=["average"], legend_pos="38%", ) line_bottom = Line() line_bottom.add( "最低气温", attr, [random.randint(20, 100) for i in range(30)], mark_point=["max", "min"], mark_line=["average"], is_yaxis_inverse=True, xaxis_pos="top", ) grid = Grid() grid.add(line_top, grid_bottom="60%") grid.add(line_bottom, grid_top="50%") grid.render()
def test_grid_add_overlap(): from pyecharts import Overlap grid = Grid() attr = ["{}月".format(i) for i in range(1, 13)] v1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3] v2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3] v3 = [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2] bar = Bar(width=1200, height=600, title="Overlap+Grid 示例", title_pos="40%") bar.add("蒸发量", attr, v1) bar.add("降水量", attr, v2, yaxis_formatter=" ml", yaxis_max=250, legend_pos="85%", legend_orient="vertical", legend_top="45%") line = Line() line.add("平均温度", attr, v3, yaxis_formatter=" °C") overlap = Overlap() overlap.add(bar) overlap.add(line, is_add_yaxis=True, yaxis_index=1) grid.add(overlap, grid_right='20%') grid.render()
def test_grid_line_pie(): line = Line("折线图示例", width=1200) line.add( "最高气温", WEEK, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"], ) line.add( "最低气温", WEEK, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"], legend_pos="20%", ) v1 = [11, 12, 13, 10, 10, 10] pie = Pie("饼图示例", title_pos="55%") pie.add( "", CLOTHES, v1, radius=[45, 65], center=[65, 50], legend_pos="80%", legend_orient="vertical", ) grid = Grid() grid.add(line, grid_right="55%") grid.add(pie, grid_left="60%") grid.render()
def get_line(item_name, subtitle, item_name_list, item_num_list): line = Line(item_name, subtitle, title_text_size=30, subtitle_text_size=25, title_pos='center') line.add("", item_name_list, item_num_list, mark_point=["max", "min"], mark_line=["average"], title_pos='center', xaxis_interval=0, xaxis_rotate=27, xaxis_label_textsize=20, yaxis_label_textsize=20, yaxis_name_pos='end', yaxis_pos="%50") line.show_config() grid = Grid(width=1300, height=800) grid.add(line, grid_top="13%", grid_bottom="23%", grid_left="15%", grid_right="15%") out_file_name = './analyse/' + item_name + '.html' grid.render(out_file_name)
def RowAnalyse(): ''' 统计聊天条数分布 个人 ''' chatrooms = getChat.GetChatrooms(typename=2) RowNum = {} print("总聊天数:" + str(len(chatrooms))) for chatroom in chatrooms: RowNum[chatroom] = toMySQL.GetRowNum(chatroom) # sorted_list = sorted(RowNum.items(), key=operator.itemgetter(1),reverse=True) # f = open("../../rows.txt","w+",encoding="utf-8") # for i in sorted_list: # f.write(i[0]+","+str(getChat.GetWXID(i[0]))+","+str(i[1])+"\n") # f.close() data = sorted(RowNum.values(), reverse=True) x_axis = list(range(len(chatrooms))) y_axis = data bar_top = Bar("条数统计", title_pos="10%") bar_top.add("", x_axis, y_axis, yaxis_name="条数", is_xaxislabel_align=True) bar_bottom = Bar("条数统计-对数坐标", title_top="55%", title_pos="10%") bar_bottom.add("", x_axis, y_axis, yaxis_name="条数", yaxis_type='log', is_xaxislabel_align=True) grid = Grid(width=1920, height=1080) grid.add(bar_top, grid_bottom="60%") grid.add(bar_bottom, grid_top="60%") grid.render(path="../../output/row_analyse.html") grid.render(path="../../output/row_analyse.pdf")
def unicorn_china5(data): data = data.groupby(by='Industry').sum() data = data.sort_values(by='Valuation', ascending=False) data2 = data[:10]['Valuation'] data3 = data[10:]['Valuation'].sum() data2.loc['其他行业'] = data3 data2 = data2[::-1] attr = list(data2.index) value = list(data2.values) bar = Bar("独角兽公司所在行业估值对比", '互联网金融行业成香饽饽', title_pos="center") bar.add('单位(亿人民币)', attr, value, is_label_show=True, label_pos='right', xaxis_interval=0, # yaxis_roate=45, is_convert=True, legend_pos='right' ) # Grid 控制图表布局,避免坐标标签折断 grid = Grid(width=600, height=1000) # 修改图形尺寸 grid.add(bar, grid_left='15%') grid.render(path='独角兽公司所在行业估值对比.png', dpi=200)
def unicorn_china2(data): data.sort_values(by='Valuation', ascending=False, inplace=True) data = data[:20][::-1] attr = list(data['Company'].values) value = list(data['Valuation'].values) # print(value,attr) bar = Bar("大中华区独角兽公司估值前二十名", '巨无霸蚂蚁金服', title_pos="center") bar.add("单位(亿人民币)", attr, value, is_label_show=True, label_pos='right', xaxis_interval=0, yaxis_roate=45, is_convert=True, legend_pos='right' ) # Grid 控制图表布局,避免坐标标签折断 grid = Grid(width=600, height=1000) # 修改图形尺寸 grid.add(bar, grid_left='15%') grid.render(path='大中华区独角兽企业估值前二十.png', dpi=200)
def test_grid_5(): import random x_axis = [ "12a", "1a", "2a", "3a", "4a", "5a", "6a", "7a", "8a", "9a", "10a", "11a", "12p", "1p", "2p", "3p", "4p", "5p", "6p", "7p", "8p", "9p", "10p", "11p" ] y_axis = [ "Saturday", "Friday", "Thursday", "Wednesday", "Tuesday", "Monday", "Sunday" ] data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] heatmap = HeatMap("热力图示例", height=700) heatmap.add("热力图直角坐标系", x_axis, y_axis, data, is_visualmap=True, visual_top="45%", visual_text_color="#000", visual_orient='horizontal') attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图示例", title_top="52%") bar.add("商家A", attr, v1, is_stack=True) bar.add("商家B", attr, v2, is_stack=True, legend_top="50%") grid = Grid() grid.add(heatmap, grid_bottom="60%") grid.add(bar, grid_top="60%") grid.render()
def view(numList): line = Line('折线图', width=2000) atter = ['数据异常', '不及格', '及格', '良好', '优秀', '满分'] v1 = [numList[0], numList[1], numList[2], numList[3], numList[4], numList[5]] line.add('最高成绩', atter, v1, mark_point=['max'], # 标点最大值 mark_line=['average']) # 虚线位置是平均分 line.add('最低成绩', atter, v1, mark_point=['min'], legend_pos='20%') es = EffectScatter() # 调用闪烁点 es.add('', atter, v1, effect_scale=8) # 调用合并函数,再一个图表上输出 overlop = Overlap() overlop.add(line) overlop.add(es) pie = Pie('饼图', title_pos='80%') pie.add('', atter, v1, radius=[60, 30], # 控制内外半径的 center=[65, 50], legend_pos='80%', legend_orient='vertical') # 显示两个示例图的调用函数,不然会覆盖 grid = Grid() grid.add(overlop, grid_right='50%') grid.add(pie, grid_left='60%') grid.render('abc.html')
def test_grid_3(): line = Line("折线图示例", width=1200) attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] line.add("最高气温", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"]) line.add("最低气温", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"], legend_pos="20%") attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [11, 12, 13, 10, 10, 10] pie = Pie("饼图示例", title_pos="55%") pie.add("", attr, v1, radius=[45, 65], center=[65, 50], legend_pos="80%", legend_orient='vertical') grid = Grid() grid.add(line, grid_right="55%") grid.add(pie, grid_left="60%") grid.render()
def get_bar(title, name_list, num_list): '''地区统计条形图''' bar = Bar(title, page_title=title, title_text_size=30, title_pos='center') bar.add("", name_list, num_list, title_pos='center', xaxis_interval=0, xaxis_rotate=27, xaxis_label_textcolor=20, yaxis_label_textcolor=20, yaxis_name_pos='end', yaxis_pos="%50") bar.show_config() grid = Grid(width=1300, height=800) grid.add(bar, grid_top='13%', grid_bottom='23%', grid_left='15%', grid_right='15%') out_file_name = './analyse/' + title + '.html' grid.render(out_file_name)
def get_bar(item_name, item_name_list, item_num_list): subtitle = 'Leo的好友地区分布统计柱状图' bar = Bar(item_name, page_title=item_name, title_text_size=30, title_pos='center', subtitle=subtitle, subtitle_text_size=25) bar.add('', item_name_list, item_num_list, title_pos='center', xaxis_interval=0, xaxis_rotate=27, xaxis_label_textsize=20, yaxis_label_textsize=20, yaxis_name_pos='end', yaxis_pos='%50') bar.show_config() grid = Grid(width=1300, height=800) grid.add(bar, grid_top='13%', grid_bottom='23%', grid_left='15%', grid_right='15%') out_file_name = './analyse/' + item_name + '.html' grid.render(out_file_name)
def create_dash_yield(hours): """ create bar+line to show yield rate in the time interval :param: kwargs: requests parameter :return: grid: pyechart object """ data_cam0 = filmdata_all(hours=hours, cam=0) data_cam1 = filmdata_all(hours=hours, cam=1) # sort data by key data_filter_cam0 = OrderedDict( sorted(data_cam0.items(), key=lambda t: t[0])) data_filter_cam1 = OrderedDict( sorted(data_cam1.items(), key=lambda t: t[0])) attr_cam0 = list(data_filter_cam0.keys()) cam0 = list(data_filter_cam0.values()) attr_cam1 = list(data_filter_cam1.keys()) cam1 = list(data_filter_cam1.values()) bar = Bar("產能柱狀圖", height=720) bar.add( "cam0", attr_cam0, cam0, is_stack=True, ) bar.add( "cam1", attr_cam1, cam1, is_stack=True, ) line = Line("產能折線圖", title_top="50%") line.add( "cam0", attr_cam0, cam0, mark_point=["max", "min"], mark_line=["average"], ) line.add( "cam1", attr_cam1, cam1, mark_point=["max", "min"], mark_line=["average"], is_datazoom_show=True, ) grid = Grid(width='100%') grid.add(bar, grid_bottom="60%") grid.add(line, grid_top="60%") grid.render() return grid
def gen_echart(file): line_cpu = Line("NE Process CPU Utility", "(%)", page_title="ne_cpu_mem") line_mem = Line("NE Memory Utility", "(MB)", title_top="20%") line_fd = Line("NE FD Utility", "(%)", title_top="40%") line_fs = Line("NE FS Utility", "(%)", title_top="60%") line_thread = Line("NE Threads Utility", "(counter)", title_top="80%") # df=pd.read_csv(source_filename,header=None, names=range(23)) df = pd.read_csv(file + ".csv", header=None, names=[ 'date', 'cips_app_cpu', 'DSWP.out_cpu', 'rcpd_cpu', 'cfgd_cpu', 'cips_app_mem', 'DSWP.out_mem', 'rcpd_mem', 'cfgd_mem', 'free_mem', 'cips_app_fd', 'DSWP.out_fd', 'rcpd_fd', 'cfgd_fd', '/run', '/var/volatile', '/sdboot', '/sddata', '/sdlog', 'cips_app_threads', 'DSWP.out_threads', 'rcpd_threads', 'cfgd_threads' ]) date = df['date'] for item in df.columns[1:5]: line_cpu.add(item, date, df[item], is_smooth=True, legend_pos="20%") for item in df.columns[5:10]: line_mem.add(item, date, df[item], is_smooth=True, legend_pos="20%", legend_top="20%") for item in df.columns[10:14]: line_fd.add(item, date[df[item].notnull()], df[item][df[item].notnull()], is_smooth=True, legend_pos="20%", legend_top="40%") for item in df.columns[14:19]: line_fs.add(item, date[df[item].notnull()], df[item].str.replace('%', '')[df[item].str.replace( '%', '').notnull()], is_smooth=True, legend_pos="20%", legend_top="60%") for item in df.columns[19:]: line_thread.add(item, date[df[item].notnull()], df[item][df[item].notnull()], is_smooth=True, legend_pos="20%", legend_top="80%") grid = Grid(height=2500, width=1200) grid.add(line_cpu, grid_top="1.5%", grid_bottom="81.5%") grid.add(line_mem, grid_top="21.5%", grid_bottom="61.5%") grid.add(line_fd, grid_top="41.5%", grid_bottom="41.5%") grid.add(line_fs, grid_top="61.5%", grid_bottom="21.5%") grid.add(line_thread, grid_top="81.5%", grid_bottom="1.5%") grid.render(file + ".html")
def get_visual_TOP10(): bar1 = nums_Top10() bar2 = food_top10() bar3 = jd_top10() grid = Grid(height=1000) grid.add(bar1, grid_bottom="80%") grid.add(bar2, grid_top="30%", grid_bottom="50%") grid.add(bar3, grid_top="60%", grid_bottom="20%") grid.render()
def test_grid_6(): line = Line("折线图示例", width=1200, height=700) attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] line.add("最高气温", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"]) line.add("最低气温", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], legend_top="50%", mark_line=["average"], is_datazoom_show=True, datazoom_xaxis_index=[0, 1]) v1 = [[2320.26, 2320.26, 2287.3, 2362.94], [2300, 2291.3, 2288.26, 2308.38], [2295.35, 2346.5, 2295.35, 2345.92], [2347.22, 2358.98, 2337.35, 2363.8], [2360.75, 2382.48, 2347.89, 2383.76], [2383.43, 2385.42, 2371.23, 2391.82], [2377.41, 2419.02, 2369.57, 2421.15], [2425.92, 2428.15, 2417.58, 2440.38], [2411, 2433.13, 2403.3, 2437.42], [2432.68, 2334.48, 2427.7, 2441.73], [2430.69, 2418.53, 2394.22, 2433.89], [2416.62, 2432.4, 2414.4, 2443.03], [2441.91, 2421.56, 2418.43, 2444.8], [2420.26, 2382.91, 2373.53, 2427.07], [2383.49, 2397.18, 2370.61, 2397.94], [2378.82, 2325.95, 2309.17, 2378.82], [2322.94, 2314.16, 2308.76, 2330.88], [2320.62, 2325.82, 2315.01, 2338.78], [2313.74, 2293.34, 2289.89, 2340.71], [2297.77, 2313.22, 2292.03, 2324.63], [2322.32, 2365.59, 2308.92, 2366.16], [2364.54, 2359.51, 2330.86, 2369.65], [2332.08, 2273.4, 2259.25, 2333.54], [2274.81, 2326.31, 2270.1, 2328.14], [2333.61, 2347.18, 2321.6, 2351.44], [2340.44, 2324.29, 2304.27, 2352.02], [2326.42, 2318.61, 2314.59, 2333.67], [2314.68, 2310.59, 2296.58, 2320.96], [2309.16, 2286.6, 2264.83, 2333.29], [2282.17, 2263.97, 2253.25, 2286.33], [2255.77, 2270.28, 2253.31, 2276.22]] kline = Kline("K 线图示例", title_top="50%") kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1, is_datazoom_show=True) grid = Grid() grid.add(line, grid_top="60%") grid.add(kline, grid_bottom="60%") grid.render()
def all_in_line(item_name, subtitle, _counter1, _counter2, _counter3): line = Line(item_name, subtitle, title_text_size=30, subtitle_text_size=18, title_pos='center') item_name_list, item_num_list = counter2seven_list(_counter1) line.add("小群", item_name_list, item_num_list, mark_point=["max"], legend_pos='65%', xaxis_interval=0, xaxis_rotate=27, xaxis_label_textsize=20, yaxis_label_textsize=20, yaxis_name_pos='end', yaxis_pos="%50") item_name_list, item_num_list = counter2seven_list(_counter2) line.add("大群", item_name_list, item_num_list, mark_point=["max"], legend_pos='65%', xaxis_interval=0, xaxis_rotate=27, xaxis_label_textsize=20, yaxis_label_textsize=20, yaxis_name_pos='end', yaxis_pos="%50") item_name_list, item_num_list = counter2seven_list(_counter3) line.add("综合", item_name_list, item_num_list, mark_point=["max"], legend_pos='65%', xaxis_interval=0, xaxis_rotate=27, xaxis_label_textsize=20, yaxis_label_textsize=20, yaxis_name_pos='end', yaxis_pos="%50") line.show_config() grid = Grid(width=1300, height=800) grid.add(line, grid_top="13%", grid_bottom="23%", grid_left="15%", grid_right="15%") out_file_name = './analyse/' + item_name + '.html' grid.render(out_file_name)
def get_bar(name, name_list, num_list): sub_title = '好友省份来源' bar = Bar(name, page_title=name, title_text_size=30, title_pos='center', subtitle=sub_title, subtitle_text_size=25) bar.add('', name_list, num_list, title_pos='center', xaxis_interval=0, xaxis_rotate=27, xaxis_label_textsize=20, yaxis_label_textsize=20, yaxis_name_pos='end', yaxis_pos="%50") # bar.show_config() grid = Grid(width=1300, height=800) grid.add(bar, grid_top="13%", grid_bottom="23%", grid_left="15%", grid_right="15%") output_file = './chart/%s.html' % name grid.render(output_file)
def generate_top10_pic(top10): bar = Bar("CPE TOP 10") x,y = [],[] for v in top10: x.append(v[0]) y.append(int(v[1])) # to solve problem that x_label's cpe is too long bar.add('频率',x,y,xaxis_interval=0,xaxis_rotate=90,is_convert=True,is_yaxis_inverse=True) grid = Grid() grid.add(bar,grid_left="50%") grid.render(CPE_TOP10_PIC_PATH)
def gird(): ''' 混合图表 1引入 Grid 类,from pyecharts import Grid 2实例化 Grid 类,grid = Grid() ,可指定 page_title, width, height, jhost 参数。 3使用 add() 向 grid 中添加图,至少需要设置一个 grid_top, grid_bottom, grid_left, grid_right 四个参数中的一个。grid_width 和 grid_height 一般不用设置,默认即可。 4使用 render() 渲染生成 .html 文件 add(chart, grid_width=None, grid_height=None, grid_top=None, grid_bottom=None, grid_left=None, grid_right=None) chart -> chart instance 图表实例 grid_width -> str/int grid 组件的宽度。默认自适应。 grid_height -> str/int grid 组件的高度。默认自适应。 grid_top -> str/int grid 组件离容器顶部的距离。默认为 None, 有'top', 'center', 'middle'可选,也可以为百分数或者整数 grid_bottom -> str/int grid 组件离容器底部的距离。默认为 None, 有'top', 'center', 'middle'可选,也可以为百分数或者整数 grid_left -> str/int grid 组件离容器左侧的距离。默认为 None, 有'left', 'center', 'right'可选,也可以为百分数或者整数 grid_right -> str/int grid 组件离容器右侧的距离。默认为 None, 有'left', 'center', 'right'可选,也可以为百分数或者整数 ''' bar = Bar('Results of each interface test', 'Data to Jenkins', height=720) attr = ['Login', 'ShiMing', 'FangYuan', 'MenSuo'] v1 = [20, 23, 22, 44] v2 = [12, 2, 4, 6] bar.add('Test Success', attr, v1, is_stack=True) bar.add('Test Failure', attr, v2, is_stack=True) gauge = Gauge('Results of each interface test', title_color='#4F4F4F', title_top='50%') gauge.add('Login Interface Test', 'Use case completion rate', 70, abel_text_color='#6E6E6E') grid = Grid() grid.add(bar, grid_bottom='60%') grid.add(gauge, grid_top='60%') grid.render(filename)
def show_chart(self, zoom_start=50, height=1000, width=2000): grid = Grid(height=height, width=width) main_ov = self.get_main_chart(height - 200, width) vol_ov = self.get_vol_chart(200, width) grid.add(main_ov, grid_top=0, grid_bottom=220) grid.add(vol_ov, grid_top=height - 200) grid._option['legend'][1]['show'] = False grid._option['color'] = ['#145b7d', '#e0861a', '#ef232a', '#14b143'] grid.render('./{}.html'.format(self.stock_name)) return grid
def test_grid_left_right(): v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] scatter = Scatter(width=1200) scatter.add("散点图示例", v1, v2, legend_pos="70%") es = EffectScatter() es.add("动态散点图示例", [11, 11, 15, 13, 12, 13, 10], [1, -2, 2, 5, 3, 2, 0], effect_scale=6, legend_pos="20%") grid = Grid() grid.add(scatter, grid_left="60%") grid.add(es, grid_right="60%") grid.render()
def get_bar(item_name,item_name_list,item_num_list): subtitle = "微信公众号:大数据前沿" bar = Bar(item_name,page_title = item_name,title_text_size=30,title_pos='center',\ subtitle = subtitle,subtitle_text_size = 25) bar.add("", item_name_list, item_num_list,title_pos='center', xaxis_interval=0,xaxis_rotate=27,\ xaxis_label_textsize = 20,yaxis_label_textsize = 20,yaxis_name_pos='end',yaxis_pos = "%50") bar.show_config() grid = Grid(width=1300,height= 800) grid.add(bar,grid_top = "13%",grid_bottom = "23%",grid_left = "15%",grid_right = "15%") out_file_name = './analyse/'+item_name+'.html' grid.render(out_file_name)
def grid(): page = Grid(page_title="Grid Container", width=1600, height=900) hot_dog = histogram.hdc_bar() ladder = LadderDiagram.ladder_diagram() stack_bar, line = StackBar.stack_bar() stack_line = StackChart.starck_line_chart() page.add(hot_dog, grid_width=600, grid_height=300, grid_left=50, grid_top=50) page.add(ladder, grid_width=600, grid_height=300, grid_left=800, grid_top=50) page.add(stack_bar, grid_width=600, grid_height=300, grid_left=800, grid_top=450) page.add(stack_line, grid_width=600, grid_height=300, grid_left=50, grid_top=450) page.render("grid.html")
def Normal(params, filename="group_ranking", num=10, title=""): ''' num:int,横坐标数量,即显示的用户数 ''' # getNamed_list = [[basicTool.GetName(i[0]),i[1]] for i in params] id_counter_dict = dict.fromkeys([i[0] for i in params], 0) for i in params: id_counter_dict[i[0]] += 1 name_counter_dict = {} for key, value in id_counter_dict.items(): name = basicTool.GetName(key) if not name in name_counter_dict.keys(): name_counter_dict[name] = value else: name_counter_dict[name] += value name_counter_sorted_list = sorted(name_counter_dict.items(), key=lambda x: x[1], reverse=True) x_list = [i[0] for i in name_counter_sorted_list] y_list = [i[1] for i in name_counter_sorted_list] grid = Grid() bar = Bar(title=title, title_pos="40%") if len(x_list) < num: bar.add( "", x_list, y_list, is_label_show=True, xaxis_interval=0, is_xaxislabel_align=True, xaxis_rotate=30, is_xaxis_show=True, is_yaxis_show=True, # is_datazoom_show=True, is_splitline_show=False) else: bar.add( "", x_list[:num], y_list[:num], is_label_show=True, xaxis_interval=0, is_xaxislabel_align=True, xaxis_rotate=30, is_xaxis_show=True, is_yaxis_show=True, # is_datazoom_show=True, is_splitline_show=False) grid.add(bar, grid_bottom="30%") grid.render(path=filename + ".html")
def create_mix(hours): """ create bar+line to show yield rate in the time interval """ latest_film = Film.objects.order_by('-rs232_time')[0] last_time = latest_film.rs232_time - datetime.timedelta( hours=hours) #latest 24h film_datas = Film.objects.filter(rs232_time__gte=last_time) # count the yield of mins grouped = itertools.groupby( film_datas, lambda f: f.rs232_time.strftime("%Y-%m-%d %H:%M")) data_records = {day: len(list(g)) for day, g in grouped} # get all time interval data_gaps = {d: 0 for d in gen_dates(last_time, latest_film.rs232_time)} # combine missing time data_all = {**data_gaps, **data_records} # sort data by key data_filter = OrderedDict(sorted(data_all.items(), key=lambda t: t[0])) attr = list(data_filter.keys()) cam0 = list(data_filter.values()) bar = Bar("產能柱狀圖", height=720) bar.add( "cam0", attr, cam0, is_stack=True, is_datazoom_show=True, datazoom_xaxis_index=[0, 1], ) line = Line("產能折線圖", title_top="50%") line.add( "cam0", attr, cam0, mark_point=["max", "min"], mark_line=["average"], legend_top="50%", is_datazoom_show=True, ) grid = Grid(width='100%') grid.add(bar, grid_bottom="60%") grid.add(line, grid_top="60%") grid.render() return grid
def test_grid_multiple_datazoom_index(): line = Line("折线图示例", width=1200, height=700) line.add("最高气温", WEEK, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"]) line.add("最低气温", WEEK, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], legend_top="50%", mark_line=["average"], is_datazoom_show=True, datazoom_xaxis_index=[0, 1]) v1 = [[2320.26, 2320.26, 2287.3, 2362.94], [2300, 2291.3, 2288.26, 2308.38], [2295.35, 2346.5, 2295.35, 2345.92], [2347.22, 2358.98, 2337.35, 2363.8], [2360.75, 2382.48, 2347.89, 2383.76], [2383.43, 2385.42, 2371.23, 2391.82], [2377.41, 2419.02, 2369.57, 2421.15], [2425.92, 2428.15, 2417.58, 2440.38], [2411, 2433.13, 2403.3, 2437.42], [2432.68, 2334.48, 2427.7, 2441.73], [2430.69, 2418.53, 2394.22, 2433.89], [2416.62, 2432.4, 2414.4, 2443.03], [2441.91, 2421.56, 2418.43, 2444.8], [2420.26, 2382.91, 2373.53, 2427.07], [2383.49, 2397.18, 2370.61, 2397.94], [2378.82, 2325.95, 2309.17, 2378.82], [2322.94, 2314.16, 2308.76, 2330.88], [2320.62, 2325.82, 2315.01, 2338.78], [2313.74, 2293.34, 2289.89, 2340.71], [2297.77, 2313.22, 2292.03, 2324.63], [2322.32, 2365.59, 2308.92, 2366.16], [2364.54, 2359.51, 2330.86, 2369.65], [2332.08, 2273.4, 2259.25, 2333.54], [2274.81, 2326.31, 2270.1, 2328.14], [2333.61, 2347.18, 2321.6, 2351.44], [2340.44, 2324.29, 2304.27, 2352.02], [2326.42, 2318.61, 2314.59, 2333.67], [2314.68, 2310.59, 2296.58, 2320.96], [2309.16, 2286.6, 2264.83, 2333.29], [2282.17, 2263.97, 2253.25, 2286.33], [2255.77, 2270.28, 2253.31, 2276.22]] kline = Kline("K 线图示例", title_top="50%") kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1, is_datazoom_show=True) grid = Grid() grid.add(line, grid_top="60%") grid.add(kline, grid_bottom="60%") grid.render()
def test_grid_heatmap_bar(): data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] heatmap = HeatMap("热力图示例", height=700) heatmap.add("热力图直角坐标系", X_TIME, Y_WEEK, data, is_visualmap=True, visual_top="45%", visual_text_color="#000", visual_orient='horizontal') v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图示例", title_top="52%") bar.add("商家A", CLOTHES, v1, is_stack=True) bar.add("商家B", CLOTHES, v2, is_stack=True, legend_top="50%") grid = Grid() grid.add(heatmap, grid_bottom="60%") grid.add(bar, grid_top="60%") grid.render()