def radar_simple() -> Radar: c = ( Radar().add_schema( # 各项的max_值可以不同 schema=[ opts.RadarIndicatorItem(name='计算几何学', max_=100), opts.RadarIndicatorItem(name='动态规划', max_=100), opts.RadarIndicatorItem(name='图论', max_=100), opts.RadarIndicatorItem(name='搜索', max_=100), opts.RadarIndicatorItem(name='模拟', max_=100), opts.RadarIndicatorItem(name='数论', max_=100), ]).add( '旺神', [[random.randint(10, 101) for _ in range(6)]], color='red', areastyle_opts=opts.AreaStyleOpts( #设置填充的属性 opacity=0.5, color='red'), ).add( '蔡队', [[random.randint(10, 101) for _ in range(6)]], color='blue', areastyle_opts=opts.AreaStyleOpts( opacity=0.5, #透明度 color='blue'), ).set_series_opts(label_opts=opts.LabelOpts( is_show=True)).set_global_opts(title_opts=opts.TitleOpts( title='雷达图示例-ACM集训队队员能力'))) return c
def line_areastyle(): obj_l = Line() obj_l.add_xaxis(Faker.choose()) obj_l.add_yaxis("商家A", Faker.values(), areastyle_opts=opts.AreaStyleOpts(opacity=0.5)) obj_l.add_yaxis("商家B", Faker.values(), areastyle_opts=opts.AreaStyleOpts(opacity=0.5)) obj_l.set_global_opts(title_opts=opts.TitleOpts(title="Line-面积图", subtitle="副标题")) return obj_l
def memory_line() -> Line: now = time.strftime('%Y{y}%m{m}%d{d}').format(y='年', m='月', d='日') mem = memory() mem_percent_dict = mem[0] swp_percent_dict = mem[1] memory_percent_line = (Line().add_xaxis(list( mem_percent_dict.keys())).add_yaxis( '内存占用率', list(mem_percent_dict.values()), areastyle_opts=opts.AreaStyleOpts(opacity=0.5), label_opts=opts.LabelOpts(is_show=False), is_smooth=True).add_yaxis( '交换区暂用率', list(swp_percent_dict.values()), areastyle_opts=opts.AreaStyleOpts(opacity=0.5), label_opts=opts.LabelOpts(is_show=False), is_smooth=True).set_global_opts( tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"), title_opts=opts.TitleOpts(title=now + "内存使用率", pos_left="center"), yaxis_opts=opts.AxisOpts(min_=0, max_=100, split_number=10, type_="value", name='%'), legend_opts=opts.LegendOpts(pos_left="left"))) return 0, 0, 0, 0, 0, 0, memory_percent_line
def load_line() -> Line: now = time.strftime('%Y{y}%m{m}%d{d}').format(y='年', m='月', d='日') lod = load() load_1m_dict = lod[0] load_5m_dict = lod[1] load_15m_dict = lod[2] max_load = lod[3] load_line = (Line().add_xaxis(list(load_1m_dict.keys())).add_yaxis( '最近1分钟负载', list(load_1m_dict.values()), areastyle_opts=opts.AreaStyleOpts(opacity=0.5), label_opts=opts.LabelOpts(is_show=False), is_smooth=True).add_yaxis( '最近5分钟负载', list(load_5m_dict.values()), areastyle_opts=opts.AreaStyleOpts(opacity=0.5), label_opts=opts.LabelOpts(is_show=False), is_smooth=True).add_yaxis( '最近15分钟负载', list(load_15m_dict.values()), areastyle_opts=opts.AreaStyleOpts(opacity=0.5), label_opts=opts.LabelOpts(is_show=False), is_smooth=True).set_global_opts( tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"), title_opts=opts.TitleOpts(title=now + "负载", pos_left="center"), yaxis_opts=opts.AxisOpts(min_=0.0, max_=max_load, split_number=10, type_="value", name=''), legend_opts=opts.LegendOpts(pos_left="left"))) return load_line
def stacked_area_chart(self, x_data, y1_data, y2_data, flag): if (flag): (Line().add_xaxis(xaxis_data=x_data).add_yaxis( series_name="研究方向数量", stack="总量", y_axis=y1_data, areastyle_opts=opts.AreaStyleOpts(opacity=0.5), label_opts=opts.LabelOpts(is_show=False), ).add_yaxis( series_name="拟招生人数", stack="总量", y_axis=y2_data, areastyle_opts=opts.AreaStyleOpts(opacity=0.5), label_opts=opts.LabelOpts(is_show=False), ).set_global_opts( title_opts=opts.TitleOpts(title="高校研究方向折线图"), tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"), yaxis_opts=opts.AxisOpts( type_="value", axistick_opts=opts.AxisTickOpts(is_show=True), splitline_opts=opts.SplitLineOpts(is_show=True), ), xaxis_opts=opts.AxisOpts(type_="category", boundary_gap=False, name_rotate=60, name_gap=20), ).render("ReserachDirections.html")) print("绘制成功,请在同级目录下查看 ReserachDirections.html 文件!") else: print("出现错误,停止绘制图表!")
def drawer2(stage_name, data): c_schema = [ { "name": "乐", "max": 0.55, "min": 0 }, { "name": "好", "max": 0.55, "min": 0 }, { "name": "哀", "max": 0.55, "min": 0 }, { "name": '恶', "max": 0.55, "min": 0 }, { "name": "惧", "max": 0.55, "min": 0 }, ] c = (Radar().set_colors(["#CC3300"]).add_schema( schema=c_schema, shape="circle", center=["50%", "50%"], radius="80%", angleaxis_opts=opts.AngleAxisOpts( min_=0, max_=360, is_clockwise=False, interval=5, axistick_opts=opts.AxisTickOpts(is_show=False), axislabel_opts=opts.LabelOpts(is_show=False), axisline_opts=opts.AxisLineOpts(is_show=False), splitline_opts=opts.SplitLineOpts(is_show=False), ), radiusaxis_opts=opts.RadiusAxisOpts( min_=-4, max_=4, interval=2, splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), ), polar_opts=opts.PolarOpts(), splitarea_opt=opts.SplitAreaOpts(is_show=False), splitline_opt=opts.SplitLineOpts(is_show=False), ).add( series_name=stage_name, data=data, areastyle_opts=opts.AreaStyleOpts(opacity=0.1), linestyle_opts=opts.LineStyleOpts(width=3), ).render("res\\output\\multi-emotion\\image\\" + stage_name + ".html"))
def get_line_ba(self,df, init_account, stock_info): trade_dates = np.array(df.trade_date).tolist() balances = np.array((df['balance'] - init_account) / init_account).tolist() c = ( Line() .add_xaxis(trade_dates) .add_yaxis("收益率" , balances , is_smooth=True, is_hover_animation=False, linestyle_opts=opts.LineStyleOpts(width=2, opacity=0.9), label_opts=opts.LabelOpts(is_show=False), ) .set_global_opts( title_opts=opts.TitleOpts(title=stock_info['name']), xaxis_opts=opts.AxisOpts( is_scale=True, type_="category", splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1) ), ), yaxis_opts=opts.AxisOpts( is_scale=True, splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1) ), ), datazoom_opts=[ opts.DataZoomOpts( is_show=True, xaxis_index=[0], type_="slider", pos_top="90%", range_start=90, range_end=100, ), # opts.DataZoomOpts( # is_show=True, # yaxis_index=[0], # type_="slider", # orient = 'vertical', # # pos_top="90%", # pos_right="0%", # range_start=0, # range_end=100, # ), ], tooltip_opts=opts.TooltipOpts( trigger="axis", axis_pointer_type="cross", background_color="rgba(245, 245, 245, 0.8)", border_width=1, border_color="#ccc", textstyle_opts=opts.TextStyleOpts(color="#000"), ), ) ) return c
def draw_centrality(): degree_centrality = nx.degree_centrality(G) closeness_centrality = nx.closeness_centrality(G) betweenness_centrality = nx.betweenness_centrality(G) degree_centrality_sort = sorted(degree_centrality, key=lambda x: degree_centrality[x], reverse=True) closeness_centrality_sort = sorted(closeness_centrality, key=lambda x: closeness_centrality[x], reverse=True) betweenness_centrality_sort = sorted(betweenness_centrality, key=lambda x: betweenness_centrality[x], reverse=True) top_authors = sorted( [(x, degree_centrality[x] + closeness_centrality[x] + betweenness_centrality[x]) for x in set.intersection( set(betweenness_centrality_sort[:30]), set(closeness_centrality_sort[:30]), set(degree_centrality_sort[:30]))], key=lambda x: x[1], reverse=True) table = prettytable.PrettyTable( ['Rank', 'Name', 'Degree centrality', 'Closeness centrality', 'Betweenness centrality', 'Sum centrality']) [table.add_row( [index + 1, value[0], round(degree_centrality[value[0]], 3), round(closeness_centrality[value[0]], 3), round(betweenness_centrality[value[0]], 3), round(value[1], 3)]) for index, value in enumerate(top_authors)] print(table) h_authors = set.intersection( set(betweenness_centrality_sort[:15]), set(closeness_centrality_sort[:15]), set(degree_centrality_sort[:15])) data = [[G.nodes[x]["name"], [betweenness_centrality[x], closeness_centrality[x], degree_centrality[x]]] for x in h_authors[:10]] c = ( Radar() .add_schema( schema=[ opts.RadarIndicatorItem(name="Betweenness centrality [0,0.15]", max_=0.15, min_=0), opts.RadarIndicatorItem(name="Closeness centrality [0,0.6]", max_=0.6, min_=0), opts.RadarIndicatorItem(name="Degree centrality [0,0.35]", max_=0.35, min_=0), ], shape="circle", center=["50%", "50%"], radius="80%", splitarea_opt=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1) ), textstyle_opts=opts.TextStyleOpts(color="#000"), ).set_series_opts(label_opts=opts.LabelOpts(is_show=False)) ) for x in data: color = randomcolor() c.add( series_name=x[0], data=[x[1]], areastyle_opts=opts.AreaStyleOpts(opacity=0.1, color=color), linestyle_opts=opts.LineStyleOpts(width=1, color=color), label_opts=opts.LabelOpts(is_show=False) ) return c
def line_areastyle() -> Line: c = (Line().add_xaxis(Faker.choose()).add_yaxis( "商家A", Faker.values(), areastyle_opts=opts.AreaStyleOpts(opacity=0.5)).add_yaxis( "商家B", Faker.values(), areastyle_opts=opts.AreaStyleOpts(opacity=0.5)).set_global_opts( title_opts=opts.TitleOpts(title="Line-面积图"))) return c
def draw_centrality(): degree_centrality = nx.degree_centrality(G) closeness_centrality = nx.closeness_centrality(G) betweenness_centrality = nx.betweenness_centrality(G) degree_centrality_sort = sorted(degree_centrality, key=lambda x: degree_centrality[x], reverse=True) closeness_centrality_sort = sorted(closeness_centrality, key=lambda x: closeness_centrality[x], reverse=True) betweenness_centrality_sort = sorted( betweenness_centrality, key=lambda x: betweenness_centrality[x], reverse=True) h_authors = set.intersection(set(betweenness_centrality_sort[:15]), set(closeness_centrality_sort[:15]), set(degree_centrality_sort[:15])) data = [[ G.nodes[x]["name"], [ betweenness_centrality[x], closeness_centrality[x], degree_centrality[x] ] ] for x in h_authors] c = (Radar().add_schema( schema=[ opts.RadarIndicatorItem(name="Betweenness centrality [0,1]", max_=1, min_=0), opts.RadarIndicatorItem(name="Closeness centrality [0,0.6]", max_=0.6, min_=0), opts.RadarIndicatorItem(name="Degree centrality [0,0.1]", max_=0.1, min_=0), ], shape="circle", center=["50%", "50%"], radius="80%", splitarea_opt=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), textstyle_opts=opts.TextStyleOpts(color="#000"), ).set_series_opts(label_opts=opts.LabelOpts(is_show=False))) for x in data: color = randomcolor() c.add(series_name=x[0], data=[x[1]], areastyle_opts=opts.AreaStyleOpts(opacity=0.1, color=color), linestyle_opts=opts.LineStyleOpts(width=1, color=color), label_opts=opts.LabelOpts(is_show=False)) c.render("radar_angle_radius_axis.html")
def draw_Kline(self): """ 画股票的K线图,需要传入四个数据 分别是["open", "close", "high", "low"] :return: 画出图像 """ Df_s1 = Read_One_Stock(self.SC).select_col("open", "high", "low", "close", "vol", "amount") length = Df_s1.shape[0] Df_s1.sort_values("trade_date", inplace=True) Df_s1.index = list(range(length)) price = np.array(Df_s1[["open", "close", "high", "low"]]).tolist() date = np.array(Df_s1["trade_date"], dtype=np.string_).tolist() ma_value_5 = calculate_ma_n(list(Df_s1['close']), 5) ma_value_10 = calculate_ma_n(list(Df_s1['close']), 10) ma_value = np.array([ma_value_5, ma_value_10]).tolist() kline = Kline() kline.set_global_opts( xaxis_opts=opts.AxisOpts(is_scale=True), yaxis_opts=opts.AxisOpts( is_scale=True, splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), ), datazoom_opts=[opts.DataZoomOpts()], title_opts=opts.TitleOpts(title="K-Line of {}".format(self.SC)), ) kline.add_xaxis(date) kline.add_yaxis('K-Line', price) line = Line() line.add_xaxis(date) line.add_yaxis(series_name="ma5", y_axis=ma_value[0], label_opts=opts.LabelOpts(is_show=False)) line.add_yaxis(series_name="ma10", y_axis=ma_value[1], label_opts=opts.LabelOpts(is_show=False)) line.set_global_opts( xaxis_opts=opts.AxisOpts(is_scale=True), yaxis_opts=opts.AxisOpts( is_scale=True, splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), ), datazoom_opts=[opts.DataZoomOpts()], title_opts=opts.TitleOpts(title="")) kline.overlap(line) kline.render("./Plots/{} Candle Plot.html".format(self.SC))
def radar_plot(v1, v2, v3, i): m = max([max(v1[0]), max(v2[0]), max(v3[0])]) c = (Radar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT,width="640px", height="360px",bg_color="#CCCCCC")) .add_schema( shape='polygon', schema=[ opts.RadarIndicatorItem(name="焦虑", max_=m), opts.RadarIndicatorItem(name="悲伤", max_=m), opts.RadarIndicatorItem(name="愤怒", max_=m), opts.RadarIndicatorItem(name="喜悦", max_=m), opts.RadarIndicatorItem(name="感激", max_=m), opts.RadarIndicatorItem(name="信任", max_=m), ], splitarea_opt=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1) ), textstyle_opts=opts.TextStyleOpts(color="#fff"), ) .add( symbol = None, series_name="官方媒体", data=v1, linestyle_opts=opts.LineStyleOpts(width=1), areastyle_opts=opts.AreaStyleOpts(opacity=0.1), ) # .add("北京", value_bj, color=) # .add("上海", value_sh, color="#b3e4a1") # .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .add( symbol=None, series_name="大众心理", data=v2, linestyle_opts=opts.LineStyleOpts(color='#61a0a8'), areastyle_opts=opts.AreaStyleOpts(opacity=0.1,color='#61a0a8'),) ).add( series_name="自媒体", symbol=None, data=v3, areastyle_opts=opts.AreaStyleOpts(opacity=0.1,color="#fab27b"), linestyle_opts=opts.LineStyleOpts(color="#fab27b"), )\ .set_series_opts(label_opts=opts.LabelOpts(is_show=False))\ .set_global_opts( title_opts=opts.TitleOpts(title="第"+str(i+1)+"阶段心态分析"), legend_opts=opts.LegendOpts() ) return c
def heat_plot(data): n, m = data.shape x, y = np.arange(0, n, 1), np.arange(0, m, 1) x, y = np.meshgrid(x, y, indexing='ij') z = data.values.flatten() x = m - 1 - x _data = list(zip(y.flatten(), x.flatten(), z)) _data = [[int(d[0]), int(d[1]), np.round(d[2], 4)] for d in _data] h = ( HeatMap( init_opts=opts.InitOpts(width="1000px", height="300px")).add_xaxis( xaxis_data=data.columns.astype(str).tolist()).add_yaxis( series_name="", yaxis_data=data.index.astype(str).tolist()[::-1], value=_data, label_opts=opts.LabelOpts(position='inside', is_show=True, font_size=15), ).set_series_opts().set_global_opts( # toolbox_opts=opts.ToolboxOpts(is_show=True), legend_opts=opts.LegendOpts(is_show=False), tooltip_opts=opts.TooltipOpts(is_show=True, ), xaxis_opts=opts.AxisOpts( type_="category", splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), ), yaxis_opts=opts.AxisOpts( type_="category", splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), ), visualmap_opts=opts.VisualMapOpts(min_=z.min(), max_=z.max(), is_calculable=True, orient="vertical", pos_left="left"), toolbox_opts=opts.ToolboxOpts( is_show=True, feature=opts.ToolBoxFeatureOpts( save_as_image=opts.ToolBoxFeatureSaveAsImageOpts( background_color='white', connected_background_color="white", pixel_ratio=2, name="pic", ), )), )) return h
def image_host_resource(doc_path, hosts_metrics, host): options = opts.InitOpts(js_host=os.path.join(os.getcwd(), "scripts/javascript/"), animation_opts=opts.AnimationOpts(animation=False)) line1 = ( Line(options) .add_xaxis(hosts_metrics[host['ip']]['metrics']['datetime']) .add_yaxis("CPU", hosts_metrics[host['ip']]['metrics']['cpu'], is_symbol_show=False, is_smooth=True, areastyle_opts=opts.AreaStyleOpts(color=utils.JsCode( "new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:'rgb(255,158,68)'},{offset:1,color:'rgb(255,70,131)'}])"), opacity=0.5)) .add_yaxis("Memory", hosts_metrics[host['ip']]['metrics']['memory'], is_symbol_show=False, is_smooth=True) .set_series_opts(linestyle_opts=opts.LineStyleOpts(width=2)) .set_global_opts( title_opts=opts.TitleOpts(title="主机资源使用率 (%s)" % (host['ip']), title_textstyle_opts=opts.TextStyleOpts(font_size=13), subtitle=" 数据来源-健康度平台"), xaxis_opts=opts.AxisOpts(type_="time"), yaxis_opts=opts.AxisOpts( axislabel_opts=opts.LabelOpts(formatter=utils.JsCode("function(val){return val + '%';}"))) ) ) line2 = ( Line(options) .add_xaxis(hosts_metrics[host['ip']]['metrics']['datetime']) .add_yaxis("Process", hosts_metrics[host['ip']]['metrics']['process'], is_symbol_show=False, is_smooth=True, areastyle_opts=opts.AreaStyleOpts(color=utils.JsCode( "new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:'#fff'},{offset:1,color:'#61a0a8'}])"), opacity=0.5) ) .set_series_opts(linestyle_opts=opts.LineStyleOpts(width=2)) .set_global_opts( xaxis_opts=opts.AxisOpts(type_="time", position="top", axislabel_opts=opts.LabelOpts(is_show=False)), yaxis_opts=opts.AxisOpts(is_inverse=True), title_opts=opts.TitleOpts(title="应用运行数量(所有)", pos_bottom="0%", title_textstyle_opts=opts.TextStyleOpts(font_size=13)), legend_opts=opts.LegendOpts(pos_bottom="0%") ) ) grid = ( Grid(options) .add(line1, grid_opts=opts.GridOpts(pos_top=50, pos_left=50, pos_right=50, pos_bottom="50%")) .add(line2, grid_opts=opts.GridOpts(pos_top="58%", pos_left=50, pos_right=50, pos_bottom=30)) ) make_snapshot(snapshot, grid.render(os.path.join(doc_path, "render_%s.html" % (host['ip'].replace(".", "_")))), os.path.join(doc_path, "host_res_%s.png" % (host['ip'].replace(".", "_"))), pixel_ratio=1, delay=1, is_remove_html=True)
def disk_line() -> Line: total, used, free = disk() c = ( Line(init_opts=opts.InitOpts(width="1680px", height="800px")) .add_xaxis(xaxis_data=disk_dict['disk_time']) .add_yaxis( series_name="写入数据", y_axis=disk_dict['write_bytes'], areastyle_opts=opts.AreaStyleOpts(opacity=0.5), linestyle_opts=opts.LineStyleOpts(), label_opts=opts.LabelOpts(is_show=False), ) .add_yaxis( series_name="读取数据", y_axis=disk_dict['read_bytes'], yaxis_index=1, areastyle_opts=opts.AreaStyleOpts(opacity=0.5), linestyle_opts=opts.LineStyleOpts(), label_opts=opts.LabelOpts(is_show=False), ) .extend_axis( yaxis=opts.AxisOpts( name_location="start", type_="value", is_inverse=True, axistick_opts=opts.AxisTickOpts(is_show=True), splitline_opts=opts.SplitLineOpts(is_show=True), name='KB/2S' ) ) .set_global_opts( title_opts=opts.TitleOpts( title="磁盘IO", pos_left="center", pos_top="top", ), tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"), legend_opts=opts.LegendOpts(pos_left="left"), xaxis_opts=opts.AxisOpts(type_="category", boundary_gap=False), yaxis_opts=opts.AxisOpts(type_="value", name='KB/2S'), ) .set_series_opts( axisline_opts=opts.AxisLineOpts(), ) ) return total, used, free, c
def line_connect_null() -> Line: url = 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5' r_data = json.loads(requests.get(url).text) data = json.loads(r_data['data']) #初始化json数据,为dict ['chinaTotal'] #每日确诊增加数 Dailyincrease = [] a = [x['confirm'] for x in data['chinaDayList']] for i in range(len(a)): if i == 0: Dailyincrease.append(0) else: Dailyincrease.append(int(a[i]) - int(a[i-1])) #每日疑似增加数 Dailysuspect = [] a = [x['suspect'] for x in data['chinaDayList']] for i in range(len(a)): if i == 0: Dailysuspect.append(0) else: Dailysuspect.append(int(a[i]) - int(a[i-1])) c = ( Line() .add_xaxis([x['date'] for x in data['chinaDayList']]) #直接列表 .add_yaxis('确诊',[x['confirm'] for x in data['chinaDayList']]) #‘列表名,[]’ .add_yaxis('疑似',[x['suspect'] for x in data['chinaDayList']]) .add_yaxis('治愈',[x['heal'] for x in data['chinaDayList']]) .add_yaxis('死亡',[x['dead'] for x in data['chinaDayList']]) .add_yaxis('每日确诊增加数',Dailyincrease,areastyle_opts=opts.AreaStyleOpts(opacity=0.5)) #areastyle_opts=opts.AreaStyleOpts(opacity=0.5) 投射面积 .add_yaxis('每日疑似增加数',Dailysuspect,is_smooth=True) #is_smooth=True 代表平滑曲线 .set_global_opts( #title_opts=opts.TitleOpts(title="2019-nCov"), datazoom_opts=opts.DataZoomOpts(range_end=100), ) ) return c
def line_base(self, street=None) -> Line: info = {} properties = Property.objects.all() for pro in properties: info.update({pro.name: [0.6, 0.5, 1, 0.8, 1.2, 1.5, 0.9]}) date_list = get_recent_date(7) if street: info = self.get_line_data(date_list, street, info) else: info = self.get_line_all(date_list, info) c = (Line().add_xaxis(date_list)) for key in info.keys(): c.add_yaxis(key, info[key], is_smooth=True) c.set_series_opts( # areastyle_opts=opts.AreaStyleOpts(opacity=0.5), # label_opts=opts.LabelOpts(is_show=False), # linestyle_opts=opts.LineStyleOpts(width=2) areastyle_opts=opts.AreaStyleOpts(opacity=0.5), label_opts=opts.LabelOpts(is_show=False), ) c.set_global_opts( # xaxis_opts=opts.AxisOpts( # axistick_opts=opts.AxisTickOpts(is_align_with_label=True), # is_scale=False, # boundary_gap=False, # ), # title_opts=opts.TitleOpts(title="Line-面积图(紧贴 Y 轴)"), xaxis_opts=opts.AxisOpts( axistick_opts=opts.AxisTickOpts(is_align_with_label=True), is_scale=False, boundary_gap=False, ), ) c = c.dump_options_with_quotes() return c
def tail_northup(): """ 北上资金跟踪 :return: """ df = db.read("tail_northup") result_df = df.set_index(['day', 'name']).unstack('name')['share_ratio'] rs_df = ((result_df - result_df.shift()).fillna(0) * 100).applymap(lambda x: round(x)) selected = sorted(list(rs_df.iloc[-1].items()), key=lambda x: x[1], reverse=True)[0][0] c = Line() c = c.add_xaxis(rs_df.index.tolist()) for key in rs_df: is_selected = key == selected c = c.add_yaxis(key, rs_df[key].values.tolist(), is_smooth=True, is_selected=is_selected) c = c.set_series_opts( areastyle_opts=opts.AreaStyleOpts(opacity=0.5), label_opts=opts.LabelOpts(is_show=False), ) c = c.set_global_opts( title_opts=opts.TitleOpts(title="主力跟踪-北上资金", subtitle=datetime.now().strftime("%Y%m%d")), xaxis_opts=opts.AxisOpts( axistick_opts=opts.AxisTickOpts(is_align_with_label=True), is_scale=False, boundary_gap=False, ), legend_opts=opts.LegendOpts(pos_left=100, pos_top=50) ) return c
def line(self, data, xaxis=None, position=0): if not xaxis: xaxis = self.xaxis line = Line(init_opts=opts.InitOpts(**self.chart_opt)).add_xaxis(xaxis_data=xaxis) for d in data: line.add_yaxis( series_name=d["label"], y_axis=d["data"], is_smooth=True, is_selected=True, is_symbol_show=False, linestyle_opts=opts.LineStyleOpts(opacity=1), label_opts=opts.LabelOpts(is_show=False), ) line.set_global_opts( xaxis_opts=opts.AxisOpts( type_="category", grid_index=position, is_scale=True, axislabel_opts=opts.LabelOpts(is_show=False), ), yaxis_opts=opts.AxisOpts( is_scale=True, axistick_opts=opts.AxisTickOpts(is_show=False), axislabel_opts=opts.LabelOpts(is_show=False), splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1) ), ), ) return line
def get_line(x, y, y_name, x_name): print(y_name) new_bar = (Bar().add_xaxis(x)) for y_label in y: new_bar.add_yaxis( y_label, y[y_label], color="#409EFF", label_opts=opt.LabelOpts(), # is_smooth=True, markline_opts=opt.MarkLineOpts( data=[opt.MarkLineItem(type_="average")]), markpoint_opts=opt.MarkPointOpts( data=[opt.MarkPointItem(type_='max', name="最大值")])) new_bar.set_series_opts(areastyle_opts=opt.AreaStyleOpts(opacity=0.5), label_opts=opt.LabelOpts(is_show=False)) new_bar.set_global_opts( datazoom_opts=opt.DataZoomOpts(type_='inside'), legend_opts=opt.LegendOpts(is_show=True), yaxis_opts=opt.AxisOpts( name=y_name, name_textstyle_opts=opt.TextStyleOpts(color="black")), xaxis_opts=opt.AxisOpts( name=x_name, name_textstyle_opts=opt.TextStyleOpts(color="black"), type_="category", )), return new_bar.dump_options_with_quotes()
def line_pf() -> Line: c = (Line(opts.InitOpts( bg_color='#FFFFFF', width='800px', height='500px')).add_xaxis(arr).add_yaxis( "功率因数", val[13], color='LightSkyBlue', is_symbol_show=False, markline_opts=opts.MarkLineOpts( data=[opts.MarkLineItem(type_="average")]), areastyle_opts=opts.AreaStyleOpts(opacity=0.4), markpoint_opts=opts.MarkPointOpts(data=[ opts.MarkPointItem(type_="max"), opts.MarkPointItem(type_="min") ])).add_yaxis( "下限(0.9)", paras[5], linestyle_opts=opts.LineStyleOpts(width=1.5, type_='dashed'), is_symbol_show=False).set_series_opts( label_opts=opts.LabelOpts(is_show=False)).set_global_opts( title_opts=opts.TitleOpts( title='功率因数趋势图', subtitle='日期:' + df.Date.iloc[0] + ' to ' + df.Date.iloc[-1], ))) return c
def dispose_line() -> Line: x_data = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] y_data = [82, 932, 901, 934, 1290, 1330, 1320] c = ( Line() .add_xaxis(x_data) .add_yaxis( series_name="", y_axis=y_data, is_symbol_show=False, label_opts=opts.LabelOpts(is_show=False), areastyle_opts=opts.AreaStyleOpts(opacity=1, color="#40a0c0") ) # .set_global_opts( # yaxis_opts=opts.AxisOpts(is_show=False), # xaxis_opts=opts.AxisOpts(is_show=False, type_="category", boundary_gap=False) # ) .set_global_opts( tooltip_opts=opts.TooltipOpts(is_show=False), xaxis_opts=opts.AxisOpts(type_="category"), yaxis_opts=opts.AxisOpts( type_="value", axistick_opts=opts.AxisTickOpts(is_show=True), splitline_opts=opts.SplitLineOpts(is_show=True), ), ) .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}")) .dump_options_with_quotes() ) return c
def gen_line_two(self, df1): df1['datetime'] = df1['date'] + ' ' + df1['time'] dt_list1 = list(df1['datetime']) # print( len(dt_list1) ) # dt_list1 = [s[5:10] for s in dt_list1] close_list1 = df1.apply(lambda record: float(record['close']), axis=1).tolist() close_list1 = np.array(close_list1) kline = Line() kline.add_xaxis(dt_list1) kline.add_yaxis('resid', close_list1, xaxis_index=1, yaxis_index=1, label_opts=opts.LabelOpts(is_show=False)) kline.set_global_opts(yaxis_opts=opts.AxisOpts( is_scale=True, splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1))), legend_opts=opts.LegendOpts(is_show=True, pos_right="40%") #xaxis_opts=opts.AxisOpts(type_='time')) ) return kline
def bar_base() -> Kline: exchane = ccxt.okex() kline_BTC = exchane.fetch_ohlcv('BTC/USDT', timeframe=time_change) df_BTC = pd.DataFrame(kline_BTC, dtype='float') df_BTC[0] = pd.to_datetime(df_BTC[0], unit='ms') # 转换为想要的时间 date = df_BTC[0].tolist() list_BTC_USDT = np.array(df_BTC[[1, 4, 3, 2]]).tolist() c = ( Kline() .add_xaxis(date) .add_yaxis('BTC', list_BTC_USDT) .set_global_opts( yaxis_opts=opts.AxisOpts( is_scale=True, splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1) ), ), xaxis_opts=opts.AxisOpts(is_scale=True), datazoom_opts=[opts.DataZoomOpts(type_="inside")], title_opts=opts.TitleOpts(title="")) .dump_options() ) return c
def list_2line_areastyle(res_list, opts_title_name)->Line: """ 根据传入的list数据,利用pyecharts绘制Line面积图 :param res_list: :param opts_title_name: :return: """ c = ( Line(init_opts=opts.InitOpts(width="1920px", height="1080px", page_title=opts_title_name, theme=ThemeType.ROMA)) .add_xaxis(res_list[0]) .add_yaxis("A1课题", res_list[1], is_smooth=True) .add_yaxis("重点滚动课题", res_list[2], is_smooth=True) .add_yaxis("A2课题", res_list[3], is_smooth=True) .add_yaxis("B类课题", res_list[4], is_smooth=True) .add_yaxis("部软科学", res_list[5], is_smooth=True) .add_yaxis("院软科学", res_list[6], is_smooth=True) .add_yaxis("团队课题", res_list[7], is_smooth=True) .add_yaxis("支撑类", res_list[8], is_smooth=True) .set_series_opts( areastyle_opts=opts.AreaStyleOpts(opacity=0.5), label_opts=opts.LabelOpts(is_show=False), ) .set_global_opts(title_opts=opts.TitleOpts(title=opts_title_name), xaxis_opts=opts.AxisOpts( axistick_opts=opts.AxisTickOpts(is_align_with_label=True), is_scale=False, boundary_gap=False, ), ) ) return c
def stat_area_trend(): df = load_data() df['发证月份'] = [i[:7] for i in df['发证日期']] summary = df.groupby('发证月份').sum() columns_area = ['预售建筑面积', '总建筑面积', '住宅面积', '办公面积', '其他面积', '车库面积'] columns_other = ['层数', '住宅套数'] chart = Line() chart.add_xaxis(summary.index.tolist()) for column in columns_area: chart.add_yaxis(column, summary[column].tolist(), areastyle_opts=opts.AreaStyleOpts(opacity=0.1), is_smooth=True) chart.set_series_opts(label_opts=opts.LabelOpts( is_show=False), ).extend_axis(yaxis=opts.AxisOpts( axislabel_opts=opts.LabelOpts(is_show=False), is_show=False)) bar = Bar() bar.add_xaxis(summary.index.tolist()) for column in columns_other: bar.add_yaxis(column, summary[column].tolist(), yaxis_index=1) chart.overlap(bar) min_date = min(df['发证日期']) max_date = max(df['发证日期']) chart.set_global_opts(title_opts=opts.TitleOpts( title="长沙预售房屋面积变化趋势", subtitle="统计日期:{}至{},数据来源:{}".format(min_date, max_date, DATA_SOURCE)), legend_opts=opts.LegendOpts(is_show=True), toolbox_opts=opts.ToolboxOpts(is_show=True)) filename = os.path.join('..', 'assets', '01_changsha_zhufangyushou_面积趋势.html') chart.render(filename)
def report(request): """返回慢SQL历史趋势""" checksum = request.GET.get('checksum') cnt_data = ChartDao().slow_query_review_history_by_cnt(checksum) pct_data = ChartDao().slow_query_review_history_by_pct_95_time(checksum) cnt_x_data = [row[1] for row in cnt_data['rows']] cnt_y_data = [int(row[0]) for row in cnt_data['rows']] pct_y_data = [str(row[0]) for row in pct_data['rows']] line = Line(init_opts=opts.InitOpts(width='800', height='380px')) line.add_xaxis(cnt_x_data) line.add_yaxis("慢查次数", cnt_y_data, is_smooth=True, markline_opts=opts.MarkLineOpts(data=[ opts.MarkLineItem(type_="max", name='最大值'), opts.MarkLineItem(type_="average", name='平均值') ])) line.add_yaxis("慢查时长(95%)", pct_y_data, is_smooth=True, is_symbol_show=False) line.set_series_opts(areastyle_opts=opts.AreaStyleOpts(opacity=0.5, )) line.set_global_opts( title_opts=opts.TitleOpts(title='SQL历史趋势'), legend_opts=opts.LegendOpts(selected_mode='single'), xaxis_opts=opts.AxisOpts( axistick_opts=opts.AxisTickOpts(is_align_with_label=True), is_scale=False, boundary_gap=False, ), ) result = {"status": 0, "msg": '', "data": line.render_embed()} return HttpResponse(json.dumps(result), content_type='application/json')
def heliu() -> Bar: a = [1,10,100,150,180,200] #模拟确诊 b = [0,2,20,50,100,102] #模拟治愈 c = [0,1,10,15,18,18] #模拟死亡 v = list(map(lambda x: x[0]-x[1]-x[2], zip(a, b, c))) #等待治愈 x = [0,1,2,3,4,5] #模拟日 c = ( Bar(init_opts=opts.InitOpts(theme=ThemeType.VINTAGE)) #设置主题 .add_xaxis(x) #直接列表 #.add_yaxis('确诊',v,stack="stack1") .add_yaxis('死亡',c,stack="stack3") .add_yaxis('治愈',b,stack="stack3") .add_yaxis('确诊',v,stack="stack3") .set_global_opts( title_opts=opts.TitleOpts(title="2019-nCov 海外国家疫情分析", subtitle=""), toolbox_opts = opts.ToolboxOpts(is_show = True), # datazoom_opts=opts.DataZoomOpts(), ) .set_series_opts( # 设置系列配置 areastyle_opts=opts.AreaStyleOpts(opacity=0.5), label_opts=opts.LabelOpts(is_show=False), singleaxis_opts=opts.SingleAxisOpts(max_=80) ) ) return c
def gen_line(df1, symbol, price_min, price_max): #df1['datetime'] = df1['date'] + ' ' + df1['time'] df1['datetime'] = df1['date'] dt_list = list(df1['datetime']) close_list = df1.apply(lambda record: float(record['close']), axis=1).tolist() close_list = np.array(close_list) line1 = Line(init_opts=opts.InitOpts(height='700px', width='1300px')) line1.set_global_opts( yaxis_opts=opts.AxisOpts( min_=price_min, #min_=999, max_=price_max, splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), ), datazoom_opts=[ opts.DataZoomOpts( is_show=True, type_="slider", range_start=0, range_end=100, ), ], ) line1.add_xaxis(xaxis_data=dt_list) line1.add_yaxis( symbol, y_axis=close_list, ) line1.set_series_opts(label_opts=opts.LabelOpts(is_show=False)) return line1
def line_connect_null() -> Line: chinaDayList,worlddata = get_chinaDayList() #每日确诊增加数 Dailyincrease = [] a = [x['confirm'] for x in chinaDayList] for i in range(len(a)): if i == 0: Dailyincrease.append(0) else: Dailyincrease.append(int(a[i]) - int(a[i-1])) #每日疑似增加数 Dailysuspect = [] a = [x['suspect'] for x in chinaDayList] for i in range(len(a)): if i == 0: Dailysuspect.append(0) else: Dailysuspect.append(int(a[i]) - int(a[i-1])) c = ( Line() .add_xaxis([x['date'] for x in chinaDayList]) #直接列表 .add_yaxis('确诊',[x['confirm'] for x in chinaDayList]) #‘列表名,[]’ .add_yaxis('疑似',[x['suspect'] for x in chinaDayList]) .add_yaxis('治愈',[x['heal'] for x in chinaDayList]) .add_yaxis('死亡',[x['dead'] for x in chinaDayList]) .add_yaxis('每日确诊增加数',Dailyincrease,areastyle_opts=opts.AreaStyleOpts(opacity=0.5)) #areastyle_opts=opts.AreaStyleOpts(opacity=0.5) 投射面积 .add_yaxis('每日疑似增加数',Dailysuspect,is_smooth=True) #is_smooth=True 代表平滑曲线 .set_global_opts( title_opts=opts.TitleOpts(title="2019-nCov"), datazoom_opts=opts.DataZoomOpts(), ) ) return c