def job_page(job): # 需要处理的数据 city_num_list = DATA.get_the_kw_msg(lan_name=job) # 生成图表 ## 饼图 city_geo_page = Page().add( pie_yht(attr_v1=city_num_list[:20], chart_name=job + '前二十个城市各自占的比重', v1_name='城市')) ## 生成柱状图 city_bar_page = Page().add( bar_sssf(attr_v1=city_num_list[:100], chart_name=job + '每个城市中该职位数量', v1_name='城市')) return render_template( 'lan.html', title=job, top5_city=DATA.top5_city_name(), top5_lan=DATA.top5_lan_name(), top5_job=DATA.top5_job_name(), city_geo_page=city_geo_page.render_embed(), city_bar_page=city_bar_page.render_embed(), script_list=city_geo_page.get_js_dependencies() + city_bar_page.get_js_dependencies(), )
def search(): page = Page() bar = get_bar() page.add(bar) keyword = request.args.get('keyword').replace(' ', '') # 获得前端传回的keyword print(keyword) if ':' in keyword: # 判断是否是高级搜索 key = keyword.split(':')[0] # 获取传回的高级搜索关键字,如"诗人:李白",此时获取‘诗人’ value = keyword.split(':')[1] # 获取‘李白’ if key == '诗人' and value: # 判断高级搜索为‘诗人’,并且搜索内容不为空 poet = Poet.query.filter_by( name=value).first() # 在数据库中查询姓名为”李白“的诗人数据 if poet: # 如果查询到 context = { 'poet': poet, # 诗人字段信息 'poem': poet.poems # 诗人的是诗的字段信息 } return render_template('search.html', **context, chart=page.render_embed()) else: # 如果没有查询到 context = { 'message': '没有找到相关内容' # 返回信息 } return render_template('search.html', **context) # 渲染页面 elif key == '诗句' and value: # 判断高级搜索为‘诗句’,并且搜索内容不为空 如”诗句:清明“ poem = Poem.query.filter( Poem.content.contains(value)).all() # 获取全部诗句内容中包含”清明“诗句 if poem: # 如果查询到 context = { 'poem': poem # 诗的字段信息 } return render_template( 'search.html', **context, chart=page.render_embed(), host='/static/js', script_list=page.get_js_dependencies()) # 渲染页面 else: # 如果没有查询到 context = {'message': '没有找到相关内容'} return render_template('search.html', **context) # 渲染页面 else: # 普通搜索,直接搜索诗的名字 如:‘江南’ poem = Poem.query.filter_by(title=keyword).all() # 获取所有诗的名字为‘江南’的数据 if poem: # 如果查询的到 context = { 'poem': poem # 所有诗的名字为‘江南’字段信息 } return render_template( 'search.html', **context, chart=page.render_embed(), host='/static/js', script_list=page.get_js_dependencies()) # 渲染页面 else: # 如果没有查询的到 context = {'message': '没有找到相关内容'} return render_template('search.html', **context) #渲染页面
class MultiPlot: def __init__(self): self.data = '' self.timeLine = Timeline() self.page = Page() self.script_list = Bar().get_js_dependencies() def multi_plot(self, dat): self.data = dat try: for m_title, tpv1 in self.data.items(): self.timeLine = Timeline(is_auto_play=False, timeline_bottom=0) attr = tpv1['index'] for m_time in list(tpv1.columns): if m_time != 'index': tp_bar = Bar(m_time) tpv1 = tpv1.sort_values(by=m_time ,ascending=False) tp_bar.add(m_title, list(tpv1['index']), list(tpv1[m_time]), xaxis_interval=0, xaxis_rotate=30, yaxis_rotate=30,) self.timeLine.add(tp_bar, m_time) self.page.add(self.timeLine) return self.page.render_embed() except Exception as e: print('multi_plot error with {}'.format(str(e))) return None
def scatter3d(): from pyecharts import Scatter3D, Page, Bar import random page = Page() attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("3D柱状图示例") bar.add('商家A', attr, v1) bar.add('商家B', attr, v2) page.add(bar) 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 散点图 demo", width=1200, height=600) scatter3D.add("", data, is_visualmap=True, visual_range_color=range_color) page.add(scatter3D) return page.render_embed()
def city_page(city): # 需要处理的数据 lan_list, job_list = DATA.get_kw_msg_of_city(city_name=city) kw_list = DATA.get_the_city_msg(city_name=city) kw_num = DATA.get_kw_num(city=city) lan_num, job_num = DATA.get_lan_job_num(city=city) # 生成数据图表 kw_bar_page = Page().add( bar_sssf(attr_v1=kw_list, chart_name=city + '各种职位总览-柱状图', v1_name='数量')) ## 对语言的分析柱状图与饼图 lan_bar_page = Page().add( bar_sssf(attr_v1=lan_list, chart_name=city + '各语言数量-柱状图', v1_name='语言')) lan_pie_page = Page().add( pie_yht(attr_v1=lan_list, chart_name='每种语言占总数占比-饼状图', v1_name='语言')) ## 对职位的分析柱状图与饼图 job_bar_page = Page().add( bar_sssf(attr_v1=job_list, chart_name=city + '各职位数量-柱状图', v1_name='职位')) job_pie_page = Page().add( pie_yht(attr_v1=job_list, chart_name='每种职位占总数占比-饼状图', v1_name='职位')) return render_template( 'city.html', title=city, kw_list=kw_list, lan_num=lan_num, job_num=job_num, top5_city=DATA.top5_city_name(), top5_lan=DATA.top5_lan_name(), top5_job=DATA.top5_job_name(), kw_bar_page=kw_bar_page.render_embed(), lan_bar_page=lan_bar_page.render_embed(), lan_pie_page=lan_pie_page.render_embed(), job_bar_page=job_bar_page.render_embed(), job_pie_page=job_pie_page.render_embed(), script_list=kw_bar_page.get_js_dependencies() + lan_bar_page.get_js_dependencies() + lan_pie_page.get_js_dependencies() + job_bar_page.get_js_dependencies() + job_pie_page.get_js_dependencies(), )
def recommendation(): page3 = Page() sca = scatter() page3.add(sca) return render_template('recommendation.html', myechart=page3.render_embed(), host=DEFAULT_HOST, script_list=page3.get_js_dependencies())
def index(): asset_count = Asset.query.count() # 总资产数 page = Page() # 生成页面对象 # 生成服务器图 webserver_pie = webserver(asset_count) # web服务器 os_pie = webos() # 操作系统 pl_pie = pl() # 开发语言 jsf_pie = jsf() # js框架 cms_pie = cms() #cms page.add([webserver_pie, os_pie, pl_pie, jsf_pie, cms_pie]) return render_template('cms/cms_index.html', chart=page.render_embed(), host='/static/front/js', total=asset_count, script_list=page.get_js_dependencies())
def virtualization(): page2 = Page() data_clound = data_cloud() page2.add(data_clound) _bar = force() page2.add(_bar) map = _map() page2.add(map) pie = _pie() page2.add(pie) return render_template('virtualization.html', myechart=page2.render_embed(), host=DEFAULT_HOST, script_list=page2.get_js_dependencies())
def stock(): page = Page() if request.method == 'POST': stock_num = request.form['stock_num'] if stock_num: kline = k_line(stock_num) page.add(kline) if kline == 0: error = "No Such Stock, Check First" return render_template('stock.html', error=error) normalline = nomoral_line(stock_num) page.add(normalline) return render_template('stock.html', myechart=page.render_embed(), host=DEFAULT_HOST, script_list=page.get_js_dependencies()) else: return render_template('stock.html') return render_template('stock.html')
def index(): stock_basics = pd.read_hdf(app.config['FIN_TECH_HDF5'], 'stock_basics', mode='r') area_count = stock_basics.groupby('area')['code'].count().reset_index() area_sum = stock_basics.groupby('area')['totalAssets'].sum().reset_index() value_count = list(area_count['code']) attr_count = list(area_count['area']) value_sum = list(area_sum['totalAssets'].astype(int)) attr_sum = list(area_sum['area']) map_count = Map("上市公司分布-公司数", width=1200, height=600) map_count.add("", attr_count, value_count, maptype='china', is_visualmap=True, visual_range=[0, 400], is_map_symbol_show=False, visual_text_color='#000') map_sum = Map("上市公司分布-公司市值", width=1200, height=600) map_sum.add("", attr_sum, value_sum, maptype='china', is_visualmap=True, visual_range=[10000000, 1000000000], is_map_symbol_show=False, visual_text_color='#000') page = Page() page.add(map_count) page.add(map_sum) # grid = Grid(width="100%") # grid.add(map_count, grid_left="60%") # grid.add(map_sum, grid_right="60%") return render_template( 'chart.html', myechart=page.render_embed(), host=app.config['REMOTE_HOST'], # my_option=json_dumps(page.options), script_list=page.get_js_dependencies())
def pyecharts(request): """dashboard view""" # 工单数量统计 chart_dao = ChartDao() bar1 = Bar('SQL上线工单统计(数量)', width="100%") data = chart_dao.workflow_by_date(30) today = date.today() one_month_before = today - relativedelta(days=+30) attr = chart_dao.get_date_list(one_month_before, today) _dict = {} for row in data['rows']: _dict[row[0]] = row[1] value = [_dict.get(day) if _dict.get(day) else 0 for day in attr] bar1.add("月统计", attr, value, is_stack=False, legend_selectedmode='single') # 工单按组统计 pie1 = Pie('SQL上线工单统计(组)', width="100%") data = chart_dao.workflow_by_group(30) attr = [row[0] for row in data['rows']] value = [row[1] for row in data['rows']] pie1.add("月统计", attr, value, is_legend_show=False, is_label_show=True) # 工单按人统计 bar2 = Bar('SQL上线工单统计(用户)', width="100%") data = chart_dao.workflow_by_user(30) attr = [row[0] for row in data['rows']] value = [row[1] for row in data['rows']] bar2.add("月统计", attr, value, is_label_show=True) # SQL语句类型统计 pie2 = Pie("SQL上线工单统计(类型)", width="100%") data = chart_dao.sql_syntax() attr = [row[0] for row in data['rows']] value = [row[1] for row in data['rows']] pie2.add("", attr, value, is_label_show=True) # SQL查询统计(每日检索行数) line1 = Line("SQL查询统计", width="100%") attr = chart_dao.get_date_list(one_month_before, today) effect_data = chart_dao.querylog_effect_row_by_date(30) effect_dict = {} for row in effect_data['rows']: effect_dict[row[0]] = int(row[1]) effect_value = [effect_dict.get(day) if effect_dict.get(day) else 0 for day in attr] count_data = chart_dao.querylog_count_by_date(30) count_dict = {} for row in count_data['rows']: count_dict[row[0]] = int(row[1]) count_value = [count_dict.get(day) if count_dict.get(day) else 0 for day in attr] line1.add("检索行数", attr, effect_value, is_stack=False, legend_selectedmode='single', mark_point=["average"]) line1.add("检索次数", attr, count_value, is_stack=False, legend_selectedmode='single', is_smooth=True, mark_line=["max", "average"]) # SQL查询统计(用户检索行数) pie4 = Pie("SQL查询统计(用户检索行数)", width="100%") data = chart_dao.querylog_effect_row_by_user(30) attr = [row[0] for row in data['rows']] value = [int(row[1]) for row in data['rows']] pie4.add("月统计", attr, value, radius=[40, 75], is_legend_show=False, is_label_show=True) # SQL查询统计(DB检索行数) pie5 = Pie("SQL查询统计(DB检索行数)", width="100%") data = chart_dao.querylog_effect_row_by_db(30) attr = [row[0] for row in data['rows']] value = [int(row[1]) for row in data['rows']] pie5.add("月统计", attr, value, is_legend_show=False, is_label_show=True) # 可视化展示页面 page = Page() page.add(bar1) page.add(pie1) page.add(bar2) page.add(pie2) page.add(line1) page.add(pie4) page.add(pie5) myechart = page.render_embed() # 渲染配置 host = 'https://pyecharts.github.io/assets/js' # js文件源地址 script_list = page.get_js_dependencies() # 获取依赖的js文件名称(只获取当前视图需要的js) return render(request, "dashboard.html", {"myechart": myechart, "host": host, "script_list": script_list})
def dau(): # 构造Request和访问协议是否是https appDAUQuest = aop.api.UmengUappGetActiveUsersRequest() appNEWQuest = aop.api.UmengUappGetNewUsersRequest() #计算时间 now_date = datetime.now().strftime('%Y-%m-%d') start_date = (datetime.now() + timedelta(days=-30)).strftime('%Y-%m-%d') #创建字典 iosDAU = {} andDAU = {} allDAU = {} iosNEW = {} andNEW = {} allNEW = {} #IOS DAU respIOSDAU = appDAUQuest.get_response(None, appkey="5c76338bb465f50bc6001045", startDate=start_date, endDate=now_date, periodType="daily") for k in respIOSDAU['activeUserInfo']: iosDAU[k['date']] = k['value'] #IOS NEW respIOSNEW = appNEWQuest.get_response(None, appkey="5c76338bb465f50bc6001045", startDate=start_date, endDate=now_date, periodType="daily") for k in respIOSNEW['newUserInfo']: iosNEW[k['date']] = k['value'] #Android DAU respANDDAU = appDAUQuest.get_response(None, appkey="5c73a5e9f1f55699ab0000ef", startDate=start_date, endDate=now_date, periodType="daily") for k in respANDDAU['activeUserInfo']: andDAU[k['date']] = k['value'] #Android NEW respANDNEW = appNEWQuest.get_response(None, appkey="5c73a5e9f1f55699ab0000ef", startDate=start_date, endDate=now_date, periodType="daily") for k in respANDNEW['newUserInfo']: andNEW[k['date']] = k['value'] x, y = Counter(iosDAU), Counter(andDAU) allDAU = dict(x + y) x, y = Counter(iosNEW), Counter(andNEW) allNEW = dict(x + y) page = Page() #处理渲染 columns = list(allDAU.keys()) #设置DAU数据 data1 = list(iosDAU.values()) data2 = list(andDAU.values()) data3 = list(allDAU.values()) #设置NEW数据 data4 = list(iosNEW.values()) data5 = list(andNEW.values()) data6 = list(allNEW.values()) #设置柱状图的主标题与副标题 bar = Bar("DAU", "完美世界电竞App最近一个月的DAU") #添加柱状图的数据及配置项 bar.add("IOS", columns, data1, is_datazoom_show=True) bar.add("Android", columns, data2, is_datazoom_show=True) bar.add("全部", columns, data3, is_datazoom_show=True) line = Line("Line Chart Demo") line.add("全部", columns, data3, is_smooth=True) overlap = Overlap(height=500, width=1200) overlap.add(bar) overlap.add(line) #设置柱状图的主标题与副标题 bar = Bar("NEW USER", "完美世界电竞App最近一个月的新增用户") #添加柱状图的数据及配置项 bar.add("IOS", columns, data4, is_datazoom_show=True) bar.add("Android", columns, data5, is_datazoom_show=True) bar.add("全部", columns, data6, is_datazoom_show=True) line = Line("Line Chart Demo") line.add("全部", columns, data6, is_smooth=True) overlap2 = Overlap(height=500, width=1200) overlap2.add(bar) overlap2.add(line) page.add(overlap) page.add(overlap2) #生成本地文件(默认为.html文件) return render_template('bar.html', myechart=page.render_embed(), script_list=page.get_js_dependencies())
def home(): """ 主页信息 """ # 将要显示的数据 print('test') city_num_list = CITY_NUM_LIST[:100] kw_num_city_list = KW_NUM_OF_ALL_CITY_LIST[:100] lan_num_list = LAN_NUM_LIST job_num_list = JOB_NUM_LIST all_num = ALL_NUM # 生成相应的图表 top_10_city_page = Page() top_10_city_page.add( bar_ssdd( attr_v1_v2=kw_num_city_list[:10], chart_name='前十城市中语言数与职位数对比-折线图', v1_name='语言数量', v2_name='职位数量', )) top_10_city_map_page = Page() top_10_city_map_page.add( geo_qgtd(attr_v1=city_num_list[:10], chart_name='前十城市地理位置', v1_name='城市')) top_100_city_page = Page() top_100_city_page.add( bar_sssf(attr_v1=city_num_list, chart_name='前百城市职位数量-柱状图', v1_name='职位数')) top_100_city_map_page = Page() top_100_city_map_page.add( geo_qgtd(attr_v1=city_num_list[:100], chart_name='前百城市地理位置', v1_name='城市')) lan_page = Page() lan_page.add( pie_yht(attr_v1=lan_num_list, chart_name='各种语言占总数比值-饼图', v1_name='语言')) job_page = Page() job_page.add( pie_yht(attr_v1=job_num_list, chart_name='各种职位占总数比值-饼图', v1_name='职位')) return render_template( 'index.html', title='首页', all_num=all_num, top5_city=DATA.top5_city_name(), top5_lan=DATA.top5_lan_name(), top5_job=DATA.top5_job_name(), top_10_city=top_10_city_page.render_embed(), top_10_city_map_page=top_10_city_map_page.render_embed(), top_100_city_page=top_100_city_page.render_embed(), top_100_city_map_page=top_100_city_map_page.render_embed(), lan_page=lan_page.render_embed(), job_page=job_page.render_embed(), script_list=top_10_city_page.get_js_dependencies() + top_100_city_page.get_js_dependencies() + lan_page.get_js_dependencies() + job_page.get_js_dependencies() + top_10_city_map_page.get_js_dependencies() + top_100_city_map_page.get_js_dependencies(), )
def events(): #构造Request和访问协议是否是https req = aop.api.UmengUappEventListRequest() #得到时间 get_date = request.args.get("date") if is_valid_date(get_date) == False: now_date = datetime.now().strftime('%Y-%m-%d') else: now_date = get_date AndEvents = {} IosEvents = {} allEvents = {} resp = req.get_response(None, appkey="5c73a5e9f1f55699ab0000ef", startDate=now_date, endDate=now_date, perPage=30, page=1, version="") AndEvents[now_date] = {} for k in resp['eventInfo']: AndEvents[now_date][k['displayName']] = k['count'] resp = req.get_response(None, appkey="5c76338bb465f50bc6001045", startDate=now_date, endDate=now_date, perPage=30, page=1, version="") IosEvents[now_date] = {} for k in resp['eventInfo']: IosEvents[now_date][k['displayName']] = k['count'] x, y = Counter(AndEvents[now_date]), Counter(IosEvents[now_date]) allEvents[now_date] = {} allEvents[now_date] = dict(x + y) resIosEvents = {} resAndEvents = {} for k in allEvents[now_date].keys(): if k not in AndEvents[now_date]: resAndEvents[k] = 0 else: resAndEvents[k] = AndEvents[now_date][k] if k not in IosEvents[now_date]: resIosEvents[k] = 0 else: resIosEvents[k] = IosEvents[now_date][k] page = Page() #处理渲染 columns = list(allEvents[now_date].keys()) #设置DAU数据 data1 = list(resIosEvents.values()) data2 = list(resAndEvents.values()) data3 = list(allEvents[now_date].values()) #设置柱状图的主标题与副标题 bar = Bar("EVENTS", "完美世界电竞App的事件消息数:" + now_date) #添加柱状图的数据及配置项 bar.add("IOS", columns, data1, is_more_utils=True, xaxis_label_textsize=10, is_datazoom_show=True) bar.add("Android", columns, data2, is_more_utils=True, xaxis_label_textsize=10) bar.add("全部", columns, data3, is_more_utils=True, xaxis_label_textsize=10, xaxis_interval=-10, xaxis_rotate=45) overlap = Overlap(height=600, width=1600) overlap.add(bar) page.add(overlap) #生成本地文件(默认为.html文件) return render_template('events.html', myechart=page.render_embed(), script_list=page.get_js_dependencies())
def pyecharts(request): # 工单数量统计 bar1 = Bar('SQL上线工单统计(数量)', width="100%") data = chart_dao.workflow_by_date(1) begin_date = (date.today() - relativedelta(months=+1)).strftime("%Y-%m-%d") attr = chart_dao.get_date_list(begin_date, date.today().strftime("%Y-%m-%d")) dict = {} for row in data['rows']: dict[row[0]] = row[1] value = [dict.get(day) if dict.get(day) else 0 for day in attr] bar1.add("月统计", attr, value, is_stack=False, legend_selectedmode='single') # 工单按组统计 pie1 = Pie('SQL上线工单统计(组)', width="100%") data = chart_dao.workflow_by_group(1) attr = [row[0] for row in data['rows']] value = [row[1] for row in data['rows']] pie1.add("月统计", attr, value, is_legend_show=False, is_label_show=True) # 工单按人统计 bar2 = Bar('SQL上线工单统计(用户)', width="100%") data = chart_dao.workflow_by_user(1) attr = [row[0] for row in data['rows']] value = [row[1] for row in data['rows']] bar2.add("月统计", attr, value, is_label_show=True) # SQL语句类型统计 pie2 = Pie("SQL上线工单统计(类型)", width="100%") data = chart_dao.sql_syntax() attr = [row[0] for row in data['rows']] value = [row[1] for row in data['rows']] pie2.add("", attr, value, is_label_show=True) # SQL执行情况统计 pie3 = Pie("SQL上线工单统计(Inception)", width="100%") data = InceptionDao().statistic() attr = data['column_list'] if data['column_list']: value = [int(row) for row in data['rows'][0]] else: value = [] pie3.add("", attr, value, is_legend_show=False, is_label_show=True) # SQL查询统计(每日检索行数) line1 = Line("SQL查询统计", width="100%") begin_date = (date.today() - relativedelta(months=+1)).strftime("%Y-%m-%d") attr = chart_dao.get_date_list(begin_date, date.today().strftime("%Y-%m-%d")) effect_data = chart_dao.querylog_effect_row_by_date(1) effect_dict = {} for row in effect_data['rows']: effect_dict[row[0]] = int(row[1]) effect_value = [ effect_dict.get(day) if effect_dict.get(day) else 0 for day in attr ] count_data = chart_dao.querylog_count_by_date(1) count_dict = {} for row in count_data['rows']: count_dict[row[0]] = int(row[1]) count_value = [ count_dict.get(day) if count_dict.get(day) else 0 for day in attr ] line1.add("检索行数", attr, effect_value, is_stack=False, legend_selectedmode='single', mark_point=["average"]) line1.add("检索次数", attr, count_value, is_stack=False, legend_selectedmode='single', is_smooth=True, mark_line=["max", "average"]) # SQL查询统计(用户检索行数) pie4 = Pie("SQL查询统计(用户检索行数)", width="100%") data = chart_dao.querylog_effect_row_by_user(1) attr = [row[0] for row in data['rows']] value = [int(row[1]) for row in data['rows']] pie4.add("月统计", attr, value, radius=[40, 75], is_legend_show=False, is_label_show=True) # SQL查询统计(DB检索行数) pie5 = Pie("SQL查询统计(DB检索行数)", width="100%") data = chart_dao.querylog_effect_row_by_db(1) attr = [row[0] for row in data['rows']] value = [int(row[1]) for row in data['rows']] pie5.add("月统计", attr, value, is_legend_show=False, is_label_show=True) # 可视化展示页面 page = Page() page.add(bar1) page.add(pie1) page.add(bar2) page.add(pie2) page.add(pie3) page.add(line1) page.add(pie4) page.add(pie5) myechart = page.render_embed() # 渲染配置 host = 'https://pyecharts.github.io/assets/js' # js文件源地址 script_list = page.get_js_dependencies() # 获取依赖的js文件名称(只获取当前视图需要的js) return render(request, "dashboard.html", { "myechart": myechart, "host": host, "script_list": script_list })
def scatter3d(): from pyecharts import Scatter3D, Page, Map, Geo, Style, GeoLines import random style = Style(title_color="#fff", title_pos="center", width=1200, height=600, background_color='#404a59') style_geo = style.add( is_label_show=True, line_curve=0.2, line_opacity=0.6, legend_text_color="#eee", legend_pos="right", geo_effect_symbol="plane", geo_effect_symbolsize=15, label_color=['#a6c84c', '#ffa022', '#46bee9'], label_pos="right", label_formatter="{b}", label_text_color="#eee", ) page = Page() ''' Scatter3D ''' 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 scattering plot demo", width=1200, height=600) scatter3D.add("", data, is_visualmap=True, visual_range_color=range_color) page.add(scatter3D) ''' Geo ''' data = [('汕头市', 50), ('杭州市', 500)] chart = Geo("地理坐标系", **style.init_style) attr, value = chart.cast(data) chart.add("", attr, value, maptype="china", is_visualmap=True, is_legend_show=False, tooltip_formatter='{b}', label_emphasis_textsize=15, label_emphasis_pos='right') page.add(chart) data = [('北京市', 50), ('上海市', 500), ('伦敦市', 100)] chart = Geo("地理坐标系", **style.init_style) ''' 自定义城市 ''' chart.add_coordinate('伦敦市', 0.1, 51.30) attr, value = chart.cast(data) chart.add("", attr, value, maptype="world", is_visualmap=True, is_legend_show=False, tooltip_formatter='{b}', label_emphasis_textsize=15, label_emphasis_pos='right') page.add(chart) ''' GeoLines ''' data_guangzhou = [["广州", "上海"], ["广州", "北京"], ["广州", "南京"], ["广州", "重庆"], ["广州", "兰州"], ["广州", "杭州"]] charts = GeoLines("GeoLines-默认示例", **style.init_style) charts.add("从广州出发", data_guangzhou, **style_geo) page.add(charts) ''' Map ''' value = [155, 10, 66, 78] attr = ["福建", "山东", "北京", "上海"] chart = Map("全国地图", **style.init_style) chart.add("", attr, value, maptype='china', is_label_show=True) page.add(chart) value = [155, 66, 78] attr = ["宁波市", "温州市", "杭州市"] chart = Map("地图", **style.init_style) ''' is_map_symbol_show=False不带标记点 ''' chart.add("", attr, value, maptype='浙江', is_label_show=True, is_visualmap=True, visual_range=[min(value), max(value)], is_map_symbol_show=False, visual_text_color='#000') page.add(chart) return page.render_embed()
def LineAndBox_plot(self, id, geneName, list_name_mouse, list_values_mouse, others_type, list_others_data, list_special_striatum, list_special_cortex, max): grid = Page() if others_type != 0: """ 第一张图 """ overlap = Overlap() line_special = Line() # title="\tSpatio-temporal Human Developmental Brain Expression (BrainSpan)", # title_pos="left") i = 0 es = Scatter(geneName) attr = ['Early fetal\n8-9PCW', 'Early fetal\n10-12PCW', 'Early mid-fetal\n13PCW-15PCW', 'Early mid-fetal\n16PCW-18PCW', \ 'Late mid-fetal\n19PCW-23PCW', 'Late fetal\n24PCW-37PCW', 'Neonatal and early infancy\n0M(birth)-5M', \ 'Late infancy\n6M-11M', 'Early childhood\n1Y-5Y', 'Middle and late childhood\n6Y-11Y', \ 'Adolescence\n12Y-19Y', 'Young adulthood\n20Y-39Y', 'Middle adulthood\n40Y'] """ 画多数值类型的拟合曲线 """ """ 1.求和 ;2.取平均值;3.画smooth """ """ 1-1 striatum """ list_linshi_striatum_ave = [0 for i in range(13)] list_linshi_striatum_num = [0 for i in range(13)] for i in range(13): if list_special_striatum[i] != []: for item in list_special_striatum[i]: list_linshi_striatum_ave[i] += item list_linshi_striatum_num[i] += 1 if list_special_striatum[i] == []: list_linshi_striatum_ave[i] = '' for i in range(13): if list_linshi_striatum_ave[i] != '': list_linshi_striatum_ave[i] = list_linshi_striatum_ave[ i] / list_linshi_striatum_num[i] line_special.add("striatum", attr, list_linshi_striatum_ave, yaxis_max=math.ceil(max), is_smooth=True, xaxis_interval=0, xaxis_type="category", xaxis_rotate=-30, xaxis_label_textsize=9, legend_selectedmode=False, legend_pos="top", legend_orient="vertical") """ 1-2 cortex """ list_linshi_cortex_ave = [0 for i in range(13)] list_linshi_cortex_num = [0 for i in range(13)] for i in range(13): if list_special_cortex[i] != []: for item in list_special_cortex[i]: list_linshi_cortex_ave[i] += item list_linshi_cortex_num[i] += 1 if list_special_cortex[i] == []: list_linshi_cortex_ave[i] = '' for i in range(13): if list_linshi_cortex_ave[i] != '': list_linshi_cortex_ave[i] = list_linshi_cortex_ave[ i] / list_linshi_cortex_num[i] line_special.add("cortex", attr, list_linshi_cortex_ave, yaxis_max=math.ceil(max), is_smooth=True, xaxis_interval=0, xaxis_type="category", xaxis_rotate=-30, xaxis_label_textsize=9, legend_selectedmode=False, yaxis_name='LOG2(RPKM+1)', yaxis_name_pos='middle', legend_pos="10%", legend_orient="horizontal") overlap.add(line_special) """ 先补齐list """ max_length_striatum = 0 for item in list_special_striatum: if len(item) >= max_length_striatum: max_length_striatum = len(item) for i in range(13): if len(list_special_striatum[i]) < max_length_striatum: for j in range(max_length_striatum - len(list_special_striatum[i])): list_special_striatum[i].append('') max_length_cortex = 0 for item in list_special_cortex: if len(item) >= max_length_cortex: max_length_cortex = len(item) for i in range(13): if len(list_special_cortex[i]) < max_length_cortex: for j in range(max_length_cortex - len(list_special_cortex[i])): list_special_cortex[i].append('') """ 画散点 """ """ striatum """ for i in range(max_length_striatum): list_linshi_striatum = [] for j in range(13): list_linshi_striatum.append(list_special_striatum[j][i]) # print(list_linshi_striatum) es.add("striatum", attr, list_linshi_striatum, xaxis_type="category", xaxis_rotate=-30, xaxis_interval=0, legend_selectedmode=False, yaxis_max=math.ceil(max), symbol_size=3, is_legend_show=False, xaxis_label_textsize=9, legend_pos="right", legend_orient="vertical") """ cortex """ for i in range(max_length_cortex): list_linshi_cortex = [] for j in range(13): list_linshi_cortex.append(list_special_cortex[j][i]) # print(list_linshi_cortex) es.add("cortex", attr, list_linshi_cortex, xaxis_type="category", xaxis_rotate=-30, xaxis_interval=0, legend_selectedmode=False, yaxis_max=max, symbol_size=3, is_legend_show=False, xaxis_label_textsize=9, legend_pos="right", legend_orient="vertical") overlap.add(es) """ 单数值的线 """ k = 0 for item in others_type: line = Line() line.add(str(item), attr, list_others_data[k], is_smooth=True, is_symbol_show=False, xaxis_interval=0, legend_selectedmode=False, xaxis_type="category", yaxis_max=max, xaxis_rotate=-30, xaxis_label_textsize=9, legend_pos="right", legend_orient="vertical") overlap.add(line) k += 1 grid.add(overlap) # grid.render() try: return grid.render_embed() except: return '<div><p>There is no corresponding data published yet,we will update it when such data available.</p></div>'