def duotu4_fun(): from pyecharts import Bar, Grid title = "Height For Class" df = pd.DataFrame( pd.read_csv('mycharts/class.csv', encoding='gbk', header=0)) df1 = pd.DataFrame(df['Height']) df2 = pd.DataFrame(df['Name']) dtvalue1 = [i[0] for i in df1.values] index1 = [i[0] for i in df2.values.tolist()] grid = Grid() bar = Bar(title, "Height For Class") bar.add('Height', index1, dtvalue1, is_datazoom_show=True, xaxis_interval=0, xaxis_rotate=30) grid.add(bar, grid_bottom="25%") return grid
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 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 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")
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 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 grids(data): kline = Kline(data.symbol[0]) kline.add( '', 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], ) turnover = Bar() turnover.add( '', data.index, data['turnover'].values / pow(10, 9), mark_line=['max', 'min'], is_datazoom_show=True, ) grid = Grid(page_title=data['symbol'][0], width=1800, height=900) grid.add(kline, grid_bottom='40%') grid.add(turnover, grid_top='65%') grid.show_config() return grid
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 spot_line(cnt,name): follow_spot=df[df['channel_id']==cnt] follow_spot=follow_spot.groupby(by=['spot_id','date'],as_index=False).sum()[['spot_id','date','cost_r']] spt=follow_spot[follow_spot['date'].apply(lambda x:str(x))==end_time.replace('-', '')].sort_values(by='cost_r').tail(7)['spot_id'] top_spt=follow_spot[follow_spot['spot_id'].isin(spt)] #TOP广告位 lists=[] for i,j in itertools.product(top_spt['spot_id'].drop_duplicates(),df['date'].drop_duplicates()): lists.append([i,j]) lists=pd.DataFrame(lists,columns=['spot_id','date']) top_spt=pd.merge(lists,top_spt,how='left',on=['spot_id','date']) top_spt=top_spt.fillna(0) top_spt=pd.merge(top_spt,meta_spot,how='left',left_on='spot_id',right_on='spotid') top_spt.loc[top_spt['name'].isnull(),'name']=top_spt[top_spt['name'].isnull()]['spot_id'] line = Line(name+'TOP广告位消耗') for i in top_spt['name'].drop_duplicates(): line.add(i,top_spt[top_spt['name']==i]['date'].apply(lambda x:str(x)),top_spt[top_spt['name']==i]['cost_r'].apply(lambda x:int(x)),legend_pos="84%",mark_point=['max']) # grid= Grid(width=1000,height=350) # grid.add(line,grid_right="25%") # page.add_chart(grid) ''' 涨跌幅TOP广告位 ''' lists=[] for i,j in itertools.product(follow_spot['spot_id'].drop_duplicates(),df['date'].drop_duplicates()): lists.append([i,j]) lists=pd.DataFrame(lists,columns=['spot_id','date']) follow_spt=pd.merge(lists,follow_spot,how='left',on=['spot_id','date'])#笛卡尔积 follow_spt=follow_spt.fillna(0) diff_spt=follow_spt.groupby(by='spot_id',as_index=False).diff()['cost_r'].rename('rise') diff_spt=pd.concat([follow_spt,diff_spt],axis=1) #涨幅TOP 7 spt=diff_spt[diff_spt['date'].apply(lambda x:str(x))==end_time.replace('-', '')].sort_values(by='rise').tail(7)['spot_id'] rise_spt=diff_spt[diff_spt['spot_id'].isin(spt)] #TOP广告位 rise_spt=pd.merge(rise_spt,meta_spot,how='left',left_on='spot_id',right_on='spotid') rise_spt.loc[rise_spt['name'].isnull(),'name']=rise_spt[rise_spt['name'].isnull()]['spot_id'] line1 = Line(name+'涨幅TOP广告位',width=1000,height=450) for i in rise_spt['name'].drop_duplicates(): line1.add(i,rise_spt[rise_spt['name']==i]['date'].apply(lambda x:str(x)),rise_spt[rise_spt['name']==i]['cost_r'].apply(lambda x:int(x)),legend_pos="84%") #跌幅TOP 7 spt=diff_spt[diff_spt['date'].apply(lambda x:str(x))==end_time.replace('-', '')].sort_values(by='rise').head(7)['spot_id'] fall_spt=diff_spt[diff_spt['spot_id'].isin(spt)] #TOP广告位 fall_spt=pd.merge(fall_spt,meta_spot,how='left',left_on='spot_id',right_on='spotid') fall_spt.loc[fall_spt['name'].isnull(),'name']=fall_spt[fall_spt['name'].isnull()]['spot_id'] line2 = Line(name+'跌幅TOP广告位',width=1000,height=450) for i in fall_spt['name'].drop_duplicates(): line2.add(i,fall_spt[fall_spt['name']==i]['date'].apply(lambda x:str(x)),fall_spt[fall_spt['name']==i]['cost_r'].apply(lambda x:int(x)),legend_pos="84%") #画图 grid= Grid(width=900,height=350) timeline = Timeline(timeline_bottom=0) timeline.add(line, name+'TOP消耗') timeline.add(line1, name+'涨幅TOP消耗') timeline.add(line2, name+'跌幅TOP消耗') grid.add(timeline) # grid= Grid(width=1200,height=350) # grid.add(line,grid_right="55%") # grid.add(line1,grid_left="55%") page.add_chart(grid)
def draw(self): line_price = Line() line_price.add('Close', self.price_timeline, self.data_price, is_datazoom_show=True, datazoom_type='both', datazoom_xaxis_index=[0, 1], is_fill=False, line_opacity=0.8, is_smooth=True) line_pe = Line() line_pe.add('EPS', self.pe_timeline, self.data_pe, is_fill=False, line_opacity=0.8, is_smooth=True, legend_top='58%') grid = Grid(width=1000, height=700) grid.add(line_price, grid_bottom="50%") grid.add(line_pe, grid_top="60%") page = Page() page.add(grid) page.render()
def stream_status(streams, is_reload=0): grid = Grid(width="100%", height="100%") # stream_time = ['00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', # '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', # '22:00', '23:00', '24:00'] # stream_in = [13, 6, 22, 5, 58, 3, 75, 98, 48, 83, 8, 38, 89, 99, 8, 21, 77, 86, 47, 76, 31, 92, 77, 47, 0] # stream_out = [5, 81, 99, 83, 55, 89, 58, 5, 38, 76, 46, 17, 68, 4, 12, 81, 2, 73, 54, 71, 50, 28, 90, 46, 0] stream_time = list(streams.keys()) val = list(streams.values()) stream_in = [v[0] for v in val] stream_out = [v[1] for v in val] stream = Line(' 进出口流量统计\n -------------------', width="100%", height="100%", title_color="#6cb7c9", title_pos="left", title_top=10) stream.add("入口流量", stream_time, stream_in, is_fill=True, line_opacity=1, line_color="#6cb7c9", label_color=["#6cb7c9", "#344356"], area_opacity=0.7, is_smooth=True, is_toolbox_show=False, is_yaxis_show=False) stream.add("出口流量", stream_time, stream_out, is_fill=True, area_color='#000', area_opacity=0.4, is_smooth=True, is_toolbox_show=False, is_yaxis_show=False, is_legend_show=True, legend_text_color="#6cb7c9", xaxis_line_color="#6cb7c9") grid.add(stream, grid_bottom=30, grid_left=30, grid_top=50, grid_right=30) if is_reload: option = grid.get_options() option = TRANSLATOR.translate(option) option = option.as_snippet() return option else: return grid
def test_grid_properties(): 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(width=1024, height=768) grid.add(bar, grid_bottom="60%") grid.add(line, grid_top="60%") eq_(grid.width, 1024) eq_(grid.height, 768) assert ('echarts' in bar.js_dependencies) or ('echarts.min' in bar.js_dependencies)
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_properties(): 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(width=1024, height=768) grid.add(bar, grid_bottom="60%") grid.add(line, grid_top="60%") eq_(grid.width, 1024) eq_(grid.height, 768) assert ( ("echarts" in bar.js_dependencies) or ("echarts.min" in bar.js_dependencies) )
def dashboard(request): tasks = Task.objects.all()[0:5] my_tasks = Task.objects.filter(tester=request.user)[0:5] attr = Results.objects.show_task_id() script_list = [] line = line_time_kf(attr) bar = bar_mp_kf(attr) # myechart = bar.render_embed() # myechart = line.render_embed() script_list.extend(line.get_js_dependencies()) # script_list = bar.get_js_dependencies() script_list.extend(bar.get_js_dependencies()) grid = Grid(width="auto") grid.add(line, grid_bottom="60%") grid.add(bar, grid_top="60%") myechart = grid.render_embed() script_list.extend(grid.get_js_dependencies()) # run_rtv_numbers = Results.objects.order_by('-id').values_list('id').first()[0] # seconds = sum([int(i[0]) for i in Results.objects.values_list('time')]) # m, s = divmod(seconds, 60) # h, m = divmod(m, 60) # d, h = divmod(h, 24) # time_cost = "%02dd:%02dh:%02dm:%02ds" % (d, h, m, s) return render(request, 'dashboard.html', { # 'run_rtv_numbers': run_rtv_numbers, # 'time_cost': time_cost, 'tasks': tasks, 'my_tasks': my_tasks, 'if_dashboard_active': 'active', 'myechart': myechart, 'script_list': script_list })
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 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 drawfunc(self, A, text, yaxis_max=200000, yaxis_force_interval=0.25, width=1000): '''坏账率绘图函数''' bar = Bar(text, title_pos='center', width='100%') line = Line(text, title_pos='center', width='100%') bar.add("好客户", A.iloc[:, 0].tolist(), A['好客户'].tolist(), yaxis_min=0, yaxis_max=yaxis_max, is_label_show=True, label_pos='inside', label_color=['#FFB6B9'], legend_pos='right', legend_orient='vertical', is_stack=True) bar.add("坏客户", A.iloc[:, 0].tolist(), A['坏账'].tolist(), yaxis_min=0, yaxis_max=yaxis_max, is_label_show=True, label_pos='inside', label_color=['#BBDED6'], legend_pos='right', legend_orient='vertical', is_stack=True) line.add('坏账率', A.iloc[:, 0].tolist(), A['坏账率'].tolist(), yaxis_min=0, yaxis_max=1, yaxis_force_interval=yaxis_force_interval, is_smooth=True, legend_pos='right', point_symbol='circle', legend_orient='vertical', line_width=2, is_label_show=True) line.add('总体坏账率', A.iloc[:, 0].tolist(), A['总体坏账率'].tolist(), yaxis_min=0, yaxis_max=1, yaxis_force_interval=yaxis_force_interval, is_smooth=True, legend_pos='right', legend_orient='vertical', line_width=2, line_type='dotted') overlap = Overlap(width='100%') overlap.add(bar) overlap.add(line, is_add_yaxis=True, yaxis_index=1) grid = Grid(width=width) grid.add(overlap, grid_right='10%') return grid
def draw(self): """ :return: """ path = self.config.get('CTP', 'navfigpath') lastNav = round(self.navDF['nav'].iloc[-1], 3) dates = self.navDF['tradingDay'].apply(lambda s: str(s.date())) grid = Grid('净值-回撤', width=2000, height=1000) l = Line('净值') nav = self.navDF['nav'].apply(lambda d: round(d, 3)).values l.add( '净值', dates, nav, # yaxis_max='dataMax', yaxis_min='dataMin', mark_point=[ "max", { "coord": [dates.iloc[-1], nav[-1]], "name": "最新" } ], # line_color=, is_legend_show=True, line_width=2, is_datazoom_show=True, ) grid.add(l, grid_bottom='55%') bar = Bar('回撤', title_top='50%') dropdown = self.navDF['dropdown'].apply(lambda d: round(d, 3)).values bar.add( '回撤', dates, dropdown, # yaxis_max='dataMax', # yaxis_min='dataMin', mark_point=[ "min", { "coord": [dates.iloc[-1], dropdown[-1]], "name": "最新" } ], is_legend_show=True, legend_top='50%', # is_datazoom_show=True, ) grid.add(bar, grid_top='55%') fn = '{}_nav.html'.format(self.userID) _path = os.path.join(path, fn) self.logger.info('生成净值 {}'.format(_path)) grid.render(_path)
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_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_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(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 duotu1_fun(): attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图示例", height=720) bar.add("商家A", attr, v1, is_stack=True) bar.add("商家B", attr, v2, is_stack=True) line = Line("折线图示例", title_top="50%") 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_top="50%", ) grid = Grid() grid.add(bar, grid_bottom="60%") grid.add(line, grid_top="60%") return grid
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 echart1(request): template = loader.get_template('ewpyecharts.html') 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"], # 设置 dataZoom 控制索引为 0,1 的 x 轴,即第一个和第二个 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("考核表分析", 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() context = dict( myechart=grid.render_embed(), host=REMOTE_HOST, script_list=grid.get_js_dependencies() ) return HttpResponse(template.render(context, request))
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 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 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 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 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_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()
ip_sales = data.loc['iPhone销售额'].values ip_unit = data.loc['iPhone销量'].values bar = Bar("iPhone销售状况") bar.add("iPhone销售额", years, ip_sales) bar2 = Bar() bar2.add("iPhone销量", years, ip_unit, bar_category_gap=25) percent = ip_sales.astype('float') / net_sales.astype('float') line = Line() line.add("收入占比", years, percent, line_width=3, yaxis_margin=60, yaxis_pos='left') ol = Overlap() ol.add(bar) ol.add(bar2, is_add_yaxis=True, yaxis_index=1) ol.add(line, is_add_yaxis=True, yaxis_index=2) grid = Grid() grid.add(ol, grid_left="15%") grid # In[189]: cn_sales = data.loc['国行'].values bar = Bar("国行销售状况") bar.add("国行", years, cn_sales) percent = cn_sales.astype('float') / net_sales.astype('float') line = Line() line.add("国行占比", years, percent, line_width=3) ol = Overlap() ol.add(bar) ol.add(line, is_add_yaxis=True, yaxis_index=1)
def test_page_grid_timeline_overlap(): # Grid 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%") # Timeline bar_1 = Bar("2012 年销量", "数据纯属虚构") bar_1.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_1.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_1.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_1.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_2 = Bar("2013 年销量", "数据纯属虚构") bar_2.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_2.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_2.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_2.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_3 = Bar("2014 年销量", "数据纯属虚构") bar_3.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_3.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_3.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_3.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_4 = Bar("2015 年销量", "数据纯属虚构") bar_4.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_4.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_4.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_4.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_5 = Bar("2016 年销量", "数据纯属虚构", height=720, width=1200) bar_5.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_5.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_5.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_5.add( "冬季", CLOTHES, [randint(10, 100) for _ in range(6)], is_legend_show=True, ) timeline = Timeline(is_auto_play=True, timeline_bottom=0) timeline.add(bar_1, "2012 年") timeline.add(bar_2, "2013 年") timeline.add(bar_3, "2014 年") timeline.add(bar_4, "2015 年") timeline.add(bar_5, "2016 年") # Overlap 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(height=720, width=1200) bar.add("蒸发量", attr, v1) bar.add("降水量", attr, v2, yaxis_formatter=" ml", yaxis_max=250) line = Line() line.add("平均温度", attr, v3, yaxis_formatter=" °C") overlap = Overlap() overlap.add(bar) overlap.add(line, yaxis_index=1, is_add_yaxis=True) page = Page() page.add(grid) page.add(timeline) page.add(overlap) page.render()
# In[14]: rank_boxoffice = [] rank_element = [] from pyecharts import Bar for i, element in enumerate(collections_detail.find({'boxoffice_num':{'$exists':True}}).sort('boxoffice_num',-1)): rank_boxoffice.append(round(element['boxoffice_num']/10000,2)) rank_element.append(element['title']) bar = Bar('2018总票房排名') bar.add('', rank_element[:10], rank_boxoffice[:10], grid_bottom=0.5, xaxis_interval=0, is_toolbox_show=False, xaxis_rotate=45, is_legend_show=False, xaxis_name='名称', yaxis_name='票房(亿)', xaxis_name_gap=100, yaxis_name_gap=30) grid = Grid() grid.add(bar, grid_bottom="30%") grid#.render('总排名.html') # 上图为2018年电影总票房前十名,‘红海行动’票房第一,共36.51亿票房。前十名中,国产电影占了5部,且票房前四名都是国产片。好的国产片能拿到越来越多的票房了。 # In[15]: genres = {} other_list = ['武侠', '悬疑', '儿童', '历史', '家庭', '古装', '传记', '纪录片', '音乐', '歌舞', '恐怖', '灾难', '运动', '同性', '西部', '戏曲'] for i, element in enumerate(collections_detail.find({'boxoffice_num':{'$exists':True}})): for genre in element['genres']: if genre in other_list: genre = '其它' if genre not in genres:
class HKUFigure(object): def __init__(self, width, height, num=1): if num < 1: self._num = 1 elif num > 4: self._num = 4 else: self._num = num self._added_flag = [False, False, False, False] self._grid = Grid(width=width, height=height) self._width = width self._height = height self._axis_num = {} self._axis_list = [None, None, None, None] for i in range(self._num): overlap = Overlap(width=width, height=height) self._axis_num[overlap] = i self._axis_list[i] = overlap self._current_axis = 0 self._xaxis = None self._label_color = [] def _repr_html_(self): return self.get_grid()._repr_html_() def get_current_axis(self): return self._axis_list[self._current_axis] def get_axis(self, pos): return self._axis_list[pos] def get_grid(self): return self._grid def set_xaxis(self, xaxis): self._xaxis = xaxis def get_xaxis(self): return self._xaxis def add_axis(self, axis): if axis not in self._axis_num: return pos = self._axis_num[axis] self._current_axis = pos self._added_flag[pos] = True self._flush() return axis def _flush(self): self._grid = Grid(width=self._width, height=self._height) for pos, axis in enumerate(self._axis_list): if axis is None or axis.options is None \ or axis.options.get('yAxis') is None: continue if self._num == 1: self._grid.add(axis, grid_top="8%") elif self._num == 2: if pos == 0: self._grid.add(axis, grid_top="8%", grid_height='52%') else: self._grid.add(axis, grid_top="62%") elif self._num == 3: if pos == 0: self._grid.add(axis, grid_top='8%', grid_height='40%') elif pos == 1: self._grid.add(axis, grid_top='50%', grid_height='19%') else: self._grid.add(axis, grid_bottom='10%', grid_height='19%') else: if pos == 0: self._grid.add(axis, grid_top='8%', grid_height='30%') elif pos == 1: self._grid.add(axis, grid_top='40%', grid_height='18%') elif pos == 2: self._grid.add(axis, grid_top='60%', grid_height='15%') else: self._grid.add(axis, grid_top='77%', grid_height='15%') def get_style(self, axis, **kwargs): pos = self._axis_num[axis] num = self._num style = Style() default_datazoom_type = 'both' result = None if num == 1: result = style.add(legend_text_size='10', legend_top='8%', legend_pos='10%', legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type) elif num == 2: if pos == 0: result = style.add(legend_text_size='10', legend_top='8%', legend_pos='10%', legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type, datazoom_xaxis_index=[0,1], is_xaxis_show=False) else: result = style.add(legend_text_size='10', legend_top='62%', legend_pos='10%', #legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type, datazoom_xaxis_index=[0,1], is_xaxis_show=True) elif num == 3: if pos == 0: result = style.add(legend_text_size='10', legend_top='8%', legend_pos='10%', legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type, datazoom_xaxis_index=[0,1,2], is_xaxis_show=False) elif pos == 1: result = style.add(legend_text_size='10', legend_top='50%', legend_pos='10%', #legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type, datazoom_xaxis_index=[0,1,2], is_xaxis_show=False) else: result = style.add(legend_text_size='10', legend_top='71%', legend_pos='10%', #legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type, datazoom_xaxis_index=[0,1,2], is_xaxis_show=True) else: if pos == 0: result = style.add(legend_text_size='10', legend_top='8%', legend_pos='10%', legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type, datazoom_xaxis_index=[0,1,2,3], is_xaxis_show=False) elif pos == 1: result = style.add(legend_text_size='10', legend_top='40%', legend_pos='10%', #legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type, datazoom_xaxis_index=[0,1,2,3], is_xaxis_show=False) elif pos == 2: result = style.add(legend_text_size='10', legend_top='60%', legend_pos='10%', #legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type, datazoom_xaxis_index=[0,1,2,3], is_xaxis_show=False) else: result = style.add(legend_text_size='10', legend_top='77%', legend_pos='10%', #legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type, datazoom_xaxis_index=[0,1,2,3], is_xaxis_show=True) color_map = {'r': '#CD0000', 'g': '#008B00', 'b': '#0000EE', 'c':'#40E0D0', 'm': '#CD00CD', 'y': '#EE9A00', 'k': '#000000', 'w': '#FFFFFF' } line_map = {'-' : 'solid', '--': 'dashed', ':' : 'dotted'} for item in kwargs.items(): if 'color' == item[0]: color = color_map[item[1]] if item[1] in color_map else color_map['r'] result['line_color'] = color self._label_color += [color] result['label_color'] = self._label_color elif 'linestyle' == item[0]: result['line_type'] = line_map[item[1]] if item[1] in line_map else line_map['-'] else: result[item[0]] = item[1] return result