def draw_order_signals(trader_name, render='html'): df_account = get_account(trader_name=trader_name) start_timestamp = df_account['timestamp'][0] end_timestamp = df_account['timestamp'][-1] df_orders = get_orders(trader_name=trader_name) grouped = df_orders.groupby('security_id') page = Page() for security_id, order_df in grouped: kdata = get_kdata(security_id=security_id, provider='netease', start_timestamp=start_timestamp, end_timestamp=end_timestamp) mark_points = order_df kline = draw_kline(df_list=[kdata], markpoints_list=[mark_points], render=None) page.add(kline) if render == 'html': file_name = '{}_signals'.format(trader_name) page.render(get_ui_path(file_name)) elif render == 'notebook': page.render_notebook() return page
def draw_account_details(trader_name, render='html'): page = Page() account_summary = draw_account_list([trader_name], render=None) # klines = draw_order_signals(trader_name=trader_name, render=None) positions = draw_positions(trader_name=trader_name, render=None) page.add(account_summary, positions) if render == 'html': file_name = '{}_details'.format(trader_name) page.render(get_ui_path(file_name)) elif render == 'notebook': page.render_notebook() return page
def page_default_layout(): page = Page() page.add( bar_datazoom_slider(), line_markpoint(), pie_rosetype(), grid_mutil_yaxis(), liquid_data_precision(), table_base(), ) put_html(page.render_notebook())
def test_page_render_notebook(): page = Page() page.add(_create_line(), _create_bar(), _create_table()) html = page.render_notebook().__html__() assert_in("City name", html)
pie_2 = (Pie().add("", [list(z) for z in zip(risk, h_20)], rosetype="radius",radius=["30%", "55%"]) .set_colors(color).set_global_opts(title_opts=opts.TitleOpts("고객 투자성향 분포: 20대")).set_series_opts(label)) tl.add(pie_2, "20대 자산 상위그룹") tl2 = Timeline() pie_0 = (Pie().add("", [list(z) for z in zip(risk, l_30)], rosetype="radius",radius=["30%", "55%"]) .set_colors(color).set_global_opts(title_opts=opts.TitleOpts("고객 투자성향 분포: 30대")).set_series_opts(label)) tl2.add(pie_0, "30대 자산 하위그룹") pie_1 = (Pie().add("", [list(z) for z in zip(risk, m_30)], rosetype="radius",radius=["30%", "55%"]) .set_colors(color).set_global_opts(title_opts=opts.TitleOpts("고객 투자성향 분포: 30대")).set_series_opts(label)) tl2.add(pie_1, "30대 자산 중위그룹") pie_2 = (Pie().add("", [list(z) for z in zip(risk, h_30)], rosetype="radius",radius=["30%", "55%"]) .set_colors(color).set_global_opts(title_opts=opts.TitleOpts("고객 투자성향 분포: 30대")).set_series_opts(label)) tl2.add(pie_2, "30대 자산 상위그룹") page = Page().add(tl,tl2) page.render_notebook() # 20대, 30대의 자산 규모 별 그룹에 따른 위험 회피정도를 시각화 해보았습니다. # # 20대의 경우 자산이 적으면 위험을 회피하려고 하지만, 30대는 자산이 적더라도 위험을 감수하려고 합니다. # 20대와 30대 모두 자산 상위그룹의 경우 위험을 감수하고자 하며, 30대의 경우 그 비율이 더 높습니다. # 이를 통해 Y&Z세대 내에서 위험을 감수하는 정도는 나이가 많아질수록, 또 자산 규모가 커질수록 높아진다고 볼 수 있습니다. # In[12]: #계좌 개수 시각화 fig = px.strip(cus_info, x="age_cat", y="num_act", color="class", category_orders={"age_cat": ["10대 미만","20대","30대","40대","50대","60대","70대 이상"],
def foregin_city_all(): file = os.getcwd() # 读取当前文件路径 path = file + '\\data\\各国各地区疫情信息' path1 = file + '\\daliy_changes_view' isExists = os.path.exists(path1) # 判断当前目录是否有文件夹photos,如果没有则创建 if not isExists: os.mkdir(path1) # 创建photos,用于存放生成的图像数据 path2 = file + '\\daliy_changes_view\\各国疫情严重程度排名前十地区信息' isExists = os.path.exists(path2) # 判断当前目录是否有文件夹daliy_changes_view,如果没有则创建 if not isExists: os.mkdir(path2) # 创建daliy_changes_view,用于存放生成的图像数据 Filelist = [] # 将当前文件夹内的所有表名存放此列表 for home, dirs, files in os.walk(path): for filename in files: Filelist.append(filename) # 判断数据是否存在 def checknan(name): if np.any(pd.isnull(name)) == True: name.fillna(value="0", inplace=True) # 随机颜色生成用于制作南丁格尔玫瑰图 def randomcolor(kind): colors = [] for i in range(kind): colArr = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ] color = "" for i in range(6): color += colArr[random.randint(0, 14)] colors.append("#" + color) return colors for i in Filelist: data = pd.read_excel(file + '\\data\\各国各地区疫情信息\\%s' % (i), index=False) data_sort = data.sort_values(axis=0, ascending=False, by=['confirm']) data_message = data_sort.head(10) # 提取疫情严重程度排名前十地区的信息 n = i[:-5] # 只提取国家名,不要后缀(.xlsx) checknan(data_message['confirm']) checknan(data_message['heal']) checknan(data_message['dead']) y1_confirm = data_message['confirm'] y1_confirm = list(y1_confirm) y1_confirm = [int(i) for i in y1_confirm] y2_dead = data_message['dead'] y2_dead = list(y2_dead) y2_dead = [int(i) for i in y2_dead] y3_heal = data_message['heal'] y3_heal = list(y3_heal) y3_heal = [int(i) for i in y3_heal] name_list = [] for j in data_message['name']: name_list.append(j) x = name_list color_series = randomcolor(len(x)) # Bars = ( # Bar(init_opts=opts.InitOpts(width='1080px',height='700px')) # .add_xaxis(xaxis_data=x) # .add_yaxis(series_name='确诊人数', yaxis_data=y1_confirm) # ) page = Page() # 创建一个分页用于放所有的图像在这一分页上 #####画南丁格尔玫瑰图########## # 画出确诊人数的图 fig = Pie(init_opts=opts.InitOpts(width='500px', height='700px')) fig.add("", [list(z) for z in zip(x, y1_confirm)], radius=['30%', '135%'], center=['50%', '65%'], rosetype='area') fig.set_global_opts(title_opts=opts.TitleOpts(title=n + '疫情严重程度排名前十地区的确诊人数'), legend_opts=opts.LegendOpts(is_show=False)) fig.set_series_opts(label_opts=opts.LabelOpts( is_show=True, position='inside', font_size=12, formatter='{b}:{c}例', font_style='italic', font_weight='bold', font_family='Microsoft YaHei')) # b:province;c:num fig.set_colors(color_series) # 画出死亡人数的图 fig1 = Pie(init_opts=opts.InitOpts(width='500px', height='700px')) fig1.add("", [list(z) for z in zip(x, y2_dead)], radius=['30%', '135%'], center=['50%', '65%'], rosetype='area') fig1.set_global_opts(title_opts=opts.TitleOpts(title=n + '疫情严重程度排名前十地区的死亡人数'), legend_opts=opts.LegendOpts(is_show=False)) fig1.set_series_opts(label_opts=opts.LabelOpts( is_show=True, position='inside', font_size=12, formatter='{b}:{c}例', font_style='italic', font_weight='bold', font_family='Microsoft YaHei')) # b:province;c:num # 画出治愈人数的图 fig2 = Pie(init_opts=opts.InitOpts(width='500px', height='700px')) fig2.add("", [list(z) for z in zip(x, y3_heal)], radius=['30%', '135%'], center=['50%', '65%'], rosetype='area') fig2.set_global_opts(title_opts=opts.TitleOpts(title=n + '疫情严重程度排名前十地区的治愈人数'), legend_opts=opts.LegendOpts(is_show=False)) fig2.set_series_opts(label_opts=opts.LabelOpts( is_show=True, position='inside', font_size=12, formatter='{b}:{c}例', font_style='italic', font_weight='bold', font_family='Microsoft YaHei')) # b:province;c:num page.add(fig) # 将图像加入同一页 page.add(fig1) # 将图像加入同一页 page.add(fig2) # 将图像加入同一页 page.render_notebook() page.render(file + '\\daliy_changes_view\\各国疫情严重程度排名前十地区信息\\%s.html' % (n), index=False)
def plot(self, total_df): page = Page(layout=Page.DraggablePageLayout) dates = [date.strftime('%Y-%m-%d') for date in total_df.index] for column in total_df.columns[:]: try: tmp = total_df[[column]] tmp.fillna(method='bfill', inplace=True) # 应该用前一天,但是为了画图,这里用了后一天,对总体影响不大 ma5 = tmp.rolling(5).mean() ma5.fillna(method='bfill', inplace=True) ma5 = round(ma5, 4) ma10 = tmp.rolling(10).mean() ma10.fillna(method='bfill', inplace=True) ma10 = round(ma10, 4) ma25 = tmp.rolling(25).mean() ma25.fillna(method='bfill', inplace=True) ma25 = round(ma25, 4) ma40 = tmp.rolling(40).mean() ma40.fillna(method='bfill', inplace=True) ma40 = round(ma40, 4) upper, middle, lower = ta.BBANDS(tmp[column].values, timeperiod=25, nbdevup=2, nbdevdn=2, matype=0) c = ( Line(init_opts=opts.InitOpts(height="300px", width='100%', bg_color="white")) .add_xaxis(dates) .add_yaxis( '', tmp.values.tolist(), is_symbol_show=False, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(color="#FF0000", width=2), markpoint_opts=opts.MarkPointOpts( data=[opts.MarkPointItem(type_="min"), opts.MarkPointItem(type_="max")]) ) .add_yaxis( '', upper, is_symbol_show=False, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(color="#404040", width=0.5) # markpoint_opts=opts.MarkPointOpts(), ) .add_yaxis( '', middle, is_symbol_show=False, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(color="#404040", width=0.5) # markpoint_opts=opts.MarkPointOpts(), ) .add_yaxis( '', lower, is_symbol_show=False, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(color="#404040", width=0.5) # markpoint_opts=opts.MarkPointOpts(), ) .add_yaxis( "ma5", ma5.values.tolist(), symbol="emptyCircle", is_symbol_show=False, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(color="#0000FF", width=1) ) .add_yaxis( "ma10", ma10.values.tolist(), symbol="emptyCircle", is_symbol_show=False, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(color="#000000", width=1) ) .add_yaxis( "ma25", ma25.values.tolist(), symbol="emptyCircle", is_symbol_show=False, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(color="#006400", width=1) ) .add_yaxis( "ma40", ma40.values.tolist(), symbol="emptyCircle", is_symbol_show=False, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(color="#800080", width=1) ) .set_global_opts(title_opts=opts.TitleOpts(title=column), xaxis_opts=opts.AxisOpts(is_scale=True), yaxis_opts=opts.AxisOpts(is_scale=True, axistick_opts=opts.AxisTickOpts(is_show=True), splitline_opts=opts.SplitLineOpts(is_show=True), ), toolbox_opts=opts.ToolboxOpts( # feature=opts.ToolBoxFeatureOpts( # save_as_image=opts.ToolBoxFeatureSaveAsImageOpts( # type_="png", # background_color='white', # pixel_ratio=15)) ), tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"), datazoom_opts=[opts.DataZoomOpts(range_start=0, range_end=100), opts.DataZoomOpts(type_="inside"), ] ) .set_series_opts( label_opts=opts.LabelOpts(is_show=False), # markpoint_opts=opts.MarkPointOpts( # data=[ # opts.MarkPointItem(type_="max", name="最大值"), # opts.MarkPointItem(type_="min", name="最小值"), # opts.MarkPointItem(type_="average", name="平均值"), # ] # ), ) ) page.add(c) except: logger.warning(f'{column}画图失败') continue page.load_javascript() page.render_notebook() return page