def theme_macarons(make_new, tag): tl = Timeline(init_opts=opts.InitOpts( theme=ThemeType.MACARONS)) # theme=ThemeType.PURPLE_PASSION tl.add_schema( pos_bottom='-7px', is_auto_play=True, symbol_size=[20, 20], play_interval=2000, ) for i in range(2015, 2020): bar = Bar() bar.add_xaxis(list(make_new.columns)) bar.add_yaxis("", list(make_new.loc[i, :].values), label_opts=opts.LabelOpts(is_show=False)) bar.set_colors([ random.choice([ 'blue', 'rgba(100,255,0,0.8)', '#5793f3', '#007A99', 'yellow' ]) ]) bar.set_global_opts( xaxis_opts=opts.AxisOpts(name="", axislabel_opts={"rotate": 40}), title_opts=opts.TitleOpts("{}-{}指数".format(i, tag))) tl.add(bar, "{}年".format(str(i))) return tl
def test_bar_colors(fake_writer): c = Bar().add_xaxis(["A", "B", "C"]).add_yaxis("series0", [1, 2, 4]) c.set_colors(["#AABBCC", "#BBCCDD", "#CCDDEE"] + c.colors) c.render() _, content = fake_writer.call_args[0] assert_in("#AABBCC", content) assert_in("#BBCCDD", content) assert_in("#CCDDEE", content)
def visualization(list_len): bar = Bar() bar.set_global_opts(title_opts=opts.TitleOpts(title="热搜情绪分析")) bar.set_colors(colors="pink") bar.add_xaxis(["<0.1", "<0.2", "<0.3", "<0.4", "<0.5", "<0.6", "<0.7", "<0.8", "<0.9", "<1"]) bar.add_yaxis("信息数量", list_len) bar.render("./outPut/final.html") time.sleep(3) # 给人一种运行起来贼麻烦的仪式感 print("\n\n[√]可视化页面生成完成!")
def dsp_her(): # 显示遗传力 # page = Page(layout=Page.DraggablePageLayout) import xlrd # file = "breeding.xlsx" f1 = xlrd.open_workbook(file) sheet1 = f1.sheet_by_name('Sheet1') lst = her(file) # 接收计算的遗传力 y = [] colorArr = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ] for i in range(len(lst)): color = "#" for j in range(6): color += colorArr[random.randint(0, 14)] y.append( opts.BarItem( value=lst[i], itemstyle_opts=opts.ItemStyleOpts(color=str(color)), # itemstyle_opts=opts.ItemStyleOpts(color=color[i]) )) x_ax = [] y_ax = [] start = load_profile()[0] end = load_profile()[1] for i in range(start, end + 1): x_ax.append(sheet1.cell_value(0, i)) bar = Bar(init_opts=opts.InitOpts( #bg_color='rgba(155,250,205,0.2)', width="1800px", height="800px")) bar.set_colors(["#FF6347", "black"]) # FF6347 bar.add_xaxis(x_ax) bar.add_yaxis("遗传力", y, category_gap="60%") bar.set_series_opts( label_opts=opts.LabelOpts(is_show=False), markpoint_opts=opts.MarkPointOpts( data=[opts.MarkPointItem(type_="max", name="最大值")])) # bar.add_yaxis("商家B", [57, 134, 137, 129, 145, 60, 49]) bar.set_global_opts(title_opts=opts.TitleOpts(title="显示已有数据遗传力")) for i in range(sheet1.nrows - 1): y_ax.append(i) line = Line(init_opts=opts.InitOpts(width="1800px", height="800px")) line.add_xaxis(y_ax) line.add_yaxis(series_name="", y_axis=lst, label_opts=opts.LabelOpts(is_show=True)) picture = bar.overlap(line) return render_template("display.html", picture_options=picture.dump_options())
def dsp_cbv(): # 显示综合育种值 import xlrd # file = "breeding.xlsx" f1 = xlrd.open_workbook(file) sheet1 = f1.sheet_by_name('Sheet1') lst = cbv(file)[0] # 接收计算的早选指数 y = [] colorArr = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ] for i in range(len(lst)): color = "#" for j in range(6): color += colorArr[random.randint(0, 14)] y.append( opts.BarItem( value=lst[i], itemstyle_opts=opts.ItemStyleOpts(color=str(color)), # itemstyle_opts=opts.ItemStyleOpts(color=color[i]) )) x_ax = cbv(file)[1] # y_ax = [] bar = Bar(init_opts=opts.InitOpts( #bg_color='rgba(255,250,205,0.2)', width="1800px", height="800px")) bar.set_colors(["#FF6347", "black"]) bar.add_xaxis(x_ax) bar.add_yaxis("综合育种值", y, category_gap="80%") bar.set_series_opts( label_opts=opts.LabelOpts(is_show=False), markpoint_opts=opts.MarkPointOpts( data=[opts.MarkPointItem(type_="max", name="最大值")])) # bar.add_yaxis("商家B", [57, 134, 137, 129, 145, 60, 49]) bar.set_global_opts(title_opts=opts.TitleOpts(title="显示已有数据综合育种值")) # for i in range(sheet1.nrows-1): # y_ax.append(i) # line = Line(init_opts=opts.InitOpts(width="1800px", height="800px")) # line.add_xaxis(y_ax) # line.add_yaxis(series_name="", y_axis=lst, label_opts=opts.LabelOpts(is_show=True)) picture = bar return render_template("display.html", picture_options=picture.dump_options())
def get_education_background(): bar = Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT)) bar.set_global_opts(title_opts=opts.TitleOpts(title="学历占比", ), legend_opts=opts.LegendOpts(pos_left="20%")) bar.add_xaxis(education) value = [] for i in education: where = { 'experience': { '$regex': ".*" + i + ".*" }, } count = mongodb.get_count_by_where(where) value.append(count) bar.add_yaxis("要求学历招聘", value, bar_width=20) bar.set_colors("blue") return (bar)
def _create_bar(): bar = Bar().add_xaxis(["A", "B", "C"]).add_yaxis("series0", [1, 2, 4]) bar.set_colors(["#AABBCC", "#BBCCDD", "#CCDDEE"] + bar.colors) return bar