def drawGraphRelation(): from pyecharts import Graph nodes = [{ "name": "结点1", "symbolSize": 10 }, { "name": "结点2", "symbolSize": 20 }, { "name": "结点3", "symbolSize": 30 }, { "name": "结点4", "symbolSize": 40 }, { "name": "结点5", "symbolSize": 50 }, { "name": "结点6", "symbolSize": 40 }, { "name": "结点7", "symbolSize": 30 }, { "name": "结点8", "symbolSize": 20 }] links = [] for i in nodes: for j in nodes: links.append({"source": i.get('name'), "target": j.get('name')}) graph = Graph("关系图-力引导布局示例") graph.add("", nodes, links, repulsion=8000) graph.render()
def plot_chnx_sample(): df = pd.read_csv(DATA_URL + '/fanti.edgelist', sep='\t', header=None, names=['ch1', 'ch2']) df = df.head(100) df.drop_duplicates(keep='first', inplace=True) nodes = [{ "name": ch, "symbolSize": 10 } for ch in set(df['ch1'].unique()) | set(df['ch2'].unique())] links = [{"source": value[0], "target": value[1]} for value in df.values] graph = Graph("汉字-样例关系图", width=1200, height=600) graph.add("", nodes, links, repulsion=80, layout=None, graph_edge_length=150, is_roam=True, is_label_show=True, is_legend_show=True, draggable=False, lineStyle='-.', graph_edge_symbol=['circle', 'arrow']) graph.render() context = dict(myechart=graph.render_embed(), host='/static/js', script_list=graph.get_js_dependencies()) return context
def bulild_html(result, action, disease): links = [] nodes = [] try: for triples in result: if 'drug' in triples.keys(): s = "drug:" + triples['drug']['value'].split('/')[-1] p = "action:" + action o = "gene:" + triples['gene']['value'].split('/')[-1] pp = "action:" + "cure" oo = disease else: s = "disease:" + triples['disease']['value'].split('/')[-1] p = "action:" + "relate_to" o = "gene:" + triples['gene']['value'].split('/')[-1] pp = "action:" + "cause" oo = "mutation:" + triples['mutation']['value'].split('/')[-1] mm = {"name": s, "symbolSize": 20} nn = {"name": o, "symbolSize": 20} kk = {"name": oo, "symbolSize": 20} if mm not in nodes: nodes.append(mm) if nn not in nodes: nodes.append(nn) if kk not in nodes: nodes.append(kk) links.append({"source": s, "value": p, "target": o}) links.append({"source": o, "value": pp, "target": oo}) graph = Graph("基因-疾病-药物") graph.add("", nodes, links, graph_repulsion=400) graph.render( path=r"E:\KG_DEMO\AGAC_KGQA_PART\kgqa\templates\kgqa\render.html") except TypeError: pass
def test_graph_force_layout(): links = [] for i in nodes: for j in nodes: links.append({"source": i.get('name'), "target": j.get('name')}) graph = Graph("关系图-力引导布局示例") graph.add("", nodes, links, repulsion=8000, line_color='#aaa') graph.render()
def test_graph_circular_layout(): links = [] for i in nodes: for j in nodes: links.append({"source": i.get('name'), "target": j.get('name')}) graph = Graph("关系图-环形布局示例") graph.add("", nodes, links, is_label_show=True, graph_repulsion=8000, graph_layout='circular', label_text_color=None) graph.render()
def guanxitu(): '''显示微博转发关系图''' with open("./jsonweibo.json", "r", encoding="utf-8") as f: j = json.load(f) nodes, links, categories, cont, mid, userl = j graph = Graph("微博转发关系图", width=1200, height=600) graph.add("", nodes, links, categories, label_pos="right", repulsion=50, is_legend_show=False, line_curve=0.2, label_text_color=None) # graph.show_config() graph.render()
def test_graph_official_data(): import json if PY2: import codecs with codecs.open(os.path.join("..", "json", "weibo.json"), "rb") as f: j = json.load(f) else: with open(os.path.join("..", "json", "weibo.json"), "r", encoding="utf-8") as f: j = json.load(f) nodes, links, categories, cont, mid, _ = j graph = Graph("微博转发关系图", width=1200, height=600) graph.add("", nodes, links, categories, label_pos="right", graph_repulsion=50, is_legend_show=False, line_curve=0.2, label_text_color=None) graph.render()
def drawGraphRelation1(): from pyecharts import Graph nodes = [{ "name": "结点1", "symbolSize": 10 }, { "name": "结点2", "symbolSize": 20 }, { "name": "结点3", "symbolSize": 30 }, { "name": "结点4", "symbolSize": 40 }, { "name": "结点5", "symbolSize": 50 }, { "name": "结点6", "symbolSize": 40 }, { "name": "结点7", "symbolSize": 30 }, { "name": "结点8", "symbolSize": 20 }] links = [] for i in nodes: for j in nodes: links.append({"source": i.get('name'), "target": j.get('name')}) graph = Graph("关系图-环形布局示例") graph.add( "", nodes, links, is_label_show=True, graph_repulsion=8000, graph_layout="circular", label_text_color=None, ) graph.render()
def ego_network(author , ego_dic): #ego_dic = load_pickle(dic_dir) nodes = [{'name':author, 'symbolSize':auscore[author][0]*10**6}] links = [] #print(ego_dic[author].items()) for item in ego_dic[author].items(): if item[0] not in auscore.keys(): nodes.append({'name': item[0], 'symbolSize': 5}) links.append({"source": author, "target": item[0], 'value': item[1]}) else: nodes.append({'name': item[0], 'symbolSize': auscore[item[0]][0]*10**6}) links.append({"source": author, "target": item[0], 'value': item[1]}) graph = Graph("Ego-network of %s"%author, width= 900, height = 800) graph.add("", nodes, links, is_label_show=True,label_text_color='g', repulsion=8000, is_focusnode=True, is_rotatelabel=True, is_roam=True, tooltip_formatter=formatter) graph.on(events.MOUSE_CLICK, on_click) graph.render(path='./Ego-nw-html/'+author+".html") return ego_dic[author]
def draw_graph(): nodes = [{ "name": "结点1", "symbolSize": 10 }, { "name": "结点2", "symbolSize": 20 }, { "name": "结点3", "symbolSize": 30 }, { "name": "结点4", "symbolSize": 40 }, { "name": "结点5", "symbolSize": 50 }, { "name": "结点6", "symbolSize": 40 }, { "name": "结点7", "symbolSize": 30 }, { "name": "结点8", "symbolSize": 20 }] links = [] for i in nodes: for j in nodes: links.append({"source": i.get('name'), "target": j.get('name')}) graph = Graph("关系图-环形布局示例") graph.add("", nodes, links, is_label_show=True, repulsion=8000, layout='circular', label_text_color=None) graph.show_config() graph.render()
def draw_network(self, layout="force"): """将网络可视化输出""" if self.scale > 10000: # 对于太大的网络,可视化意义不大且效率极低,故只对小型网络进行可视化 print("网络规模太大(" + str(self.scale) + "),不支持可视化!请抽取更小的子网络进行可视化") return g = self.network partition = community.best_partition(g) if layout.lower() != 'force' and layout.lower() != 'circular': raise ValueError("没有这种布局!布局请选择force或circular") # 获取节点名称映射 names = nx.get_node_attributes(g, 'name') nodes = [{ 'name': names[n], 'symbolSize': math.log2(nx.degree(g, n, weight=self.weight_type) + 1), 'category': partition[n] } for n in g.nodes()] links = [{ 'source': names[e[0]], 'target': names[e[1]], 'value': e[2][self.weight_type] } for e in g.edges] graph = Graph(self.net_type, width=1200, height=750) graph.add( "", nodes, links, categories=list(set(partition.values())), label_pos="right", graph_repulsion=50, graph_layout=layout, is_legend_show=False, line_curve=0.2, label_text_color=None, ) graph.render(self.net_type + '.html')
def echartshow(nodes, links, execlpath, Preservationpath, flogg=False): if flogg: partstr = '有收付标志' else: partstr = '无收付标志' graph = Graph(os.path.basename(execlpath).split('.')[0] + partstr + "图例", width=1920, height=1080) graph.add("", nodes, links, is_label_show=False, repulsion=50, is_focusnode=True, is_roam=True, graph_layout='force', line_color="rgba(50,50,50,0.7)", graph_edge_symbol=['circle', 'arrow']) graph.render( (str(Preservationpath) + os.path.basename(execlpath).split('.')[0] + partstr + '.html')) # if __name__ == "__main__": # execlpath = r'账户交易明细表.xls' # execlpath1=r'账户交易明细表副本.xlsx' # Preservationpath = r'result/' # sourceaccount = '交易账卡号' # targetaccount = '对手账号' # value = '交易金额' # label = '收付标志' # #xls # execlfileVisual(execlpath, Preservationpath, sourceaccount, targetaccount, value, label) # execlfileVisual(execlpath, Preservationpath, sourceaccount, targetaccount, value) # # #xlsx # execlfileVisual(execlpath1, Preservationpath, sourceaccount, targetaccount, value, label) # execlfileVisual(execlpath1, Preservationpath, sourceaccount, targetaccount, value)
def visualize(self,rangee,com_name): #可视化为名为render的html文件 nodes=[] for n in self.SnapGraph.Nodes(): if n.GetId() in rangee: size=np.sqrt(n.GetDeg()) if n.GetId() in self.topnlist: size=20 nodes.append({"name":n.GetId(), "symbolSize":size, "category":self.ComStructDict[com_name][n.GetId()]}) links=[] for n in self.SnapGraph.Nodes(): if n.GetId() in rangee: for j in n.GetOutEdges(): if j in rangee: links.append({"source": n.GetId(), "target": j}) graph = Graph("try") graph.add("", nodes, links,categories=self.categories[com_name], repulsion=50,line_curve=0.2, graph_edge_symbol= ['circle', 'arrow']) graph.render()
def graph_show(edge_list): nodes = [] links = [] nodes_list = [] w_min = sys.float_info.max w_max = 0 for edge in edge_list: u, v, w = edge.getLeft(), edge.getRight(), edge.getWeight() if w < w_min: w_min = w if w > w_max: w_max = w if u not in nodes_list: nodes_list.append(u) nodes.append({"name": str(u), "symbolSize": 10}) if v not in nodes_list: nodes_list.append(v) nodes.append({"name": str(v), "symbolSize": 10}) links.append({"source": str(u), "target": str(v), "value": w}) print("min w:", w_min) print("max w:", w_max) graph = Graph("Minimum Spanning Tree") graph.add("", nodes, links, graph_layout='force', graph_edge_length=[w_min, w_max], graph_gravity=0, graph_repulsion=0, is_label_show=True) graph.show_config() graph.render()
def gen_graph(csv_file): dc = read_network(csv_file) max_degree = max(dc.values()) nodes = [node for node in dc.keys() if dc[node] != 1] links = [] with open(csv_file, 'r') as f: f_csv = csv.reader(f) for row in f_csv: source, target = row if source not in nodes or target not in nodes: continue else: link = {'source': source, 'target': target} links.append(link) nodes = [{ 'name': node, 'symbolSize': math.log10(dc[node]) / math.log10(max_degree) * 20, 'value': dc[node] } for node in nodes] graph = Graph(title='微博传播网络图', width=1080, height=800) graph.add('', nodes, links, is_label_show=True, line_curve=0.2) graph.render()
def draw_relation_2(): sql = "select distinct(fid),`name`,relation_gen from renren_user_info where relation_gen < 2" nodes, categories = db_pool.execute_query_sql(sql, fetch_user_data) r_sql = """select r.fid,r.tid from renren.renren_relation r where tid in (%s)""" s = '' for node in nodes: s += "'" + node['fid'] + "'," links = db_pool.execute_query_sql(r_sql % s[0:len(s) - 1], fetch_relation_data) graph = Graph("人人好友关系", width=1200, height=600) graph.add( "", nodes, links, categories, label_pos="right", graph_repulsion=50, is_legend_show=False, line_curve=0.2, label_text_color=None, ) graph.render()
def draw_map(AS): graph = Graph("AS Links Map") nodes = [] maxDegree = 0 for key in AS: if len(AS[key]) >= maxDegree: maxDegree = len(AS[key]) for key in AS: singleNode = {"name": "AS" + key, "symbolSize": (len(AS[key]) + 1) / (maxDegree + 1) * 5} nodes.append(singleNode) links = [] for i in nodes: key = i.get('name')[2:] for j in AS[key]: links.append({"source": i.get('name'), "target": "AS" + j}) graph.add("AS Links Map", nodes, links, layout="cycle") graph.render()
def test_graph(): # graph_0 nodes = [{"name": "结点1", "symbolSize": 10}, {"name": "结点2", "symbolSize": 20}, {"name": "结点3", "symbolSize": 30}, {"name": "结点4", "symbolSize": 40}, {"name": "结点5", "symbolSize": 50}, {"name": "结点6", "symbolSize": 40}, {"name": "结点7", "symbolSize": 30}, {"name": "结点8", "symbolSize": 20}] links = [] for i in nodes: for j in nodes: links.append({"source": i.get('name'), "target": j.get('name')}) graph = Graph("关系图-力引导布局示例") graph.add("", nodes, links, repulsion=8000) graph.show_config() graph.render() # graph_1 graph = Graph("关系图-环形布局示例") graph.add("", nodes, links, is_label_show=True, graph_repulsion=8000, graph_layout='circular', label_text_color=None) graph.show_config() graph.render() # graph_2 import json if PY2: import codecs with codecs.open(os.path.join("..", "json", "weibo.json"), "rb") as f: j = json.load(f) else: with open(os.path.join("..", "json", "weibo.json"), "r", encoding="utf-8") as f: j = json.load(f) nodes, links, categories, cont, mid, userl = j graph = Graph("微博转发关系图", width=1200, height=600) graph.add("", nodes, links, categories, label_pos="right", graph_repulsion=50, is_legend_show=False, line_curve=0.2, label_text_color=None) graph.show_config() graph.render()
def test_graph(): # graph_0 nodes = [{"name": "结点1", "symbolSize": 10}, {"name": "结点2", "symbolSize": 20}, {"name": "结点3", "symbolSize": 30}, {"name": "结点4", "symbolSize": 40}, {"name": "结点5", "symbolSize": 50}, {"name": "结点6", "symbolSize": 40}, {"name": "结点7", "symbolSize": 30}, {"name": "结点8", "symbolSize": 20}] links = [] for i in nodes: for j in nodes: links.append({"source": i.get('name'), "target": j.get('name')}) graph = Graph("关系图-力引导布局示例") graph.add("", nodes, links, repulsion=8000) graph.show_config() graph.render() # graph_1 graph = Graph("关系图-环形布局示例") graph.add("", nodes, links, is_label_show=True, repulsion=8000, layout='circular', label_text_color=None) graph.show_config() graph.render() # graph_2 import json if PY2: import codecs with codecs.open(os.path.join("..", "json", "weibo.json"), "rb") as f: j = json.load(f) else: with open(os.path.join("..", "json", "weibo.json"), "r", encoding="utf-8") as f: j = json.load(f) nodes, links, categories, cont, mid, userl = j graph = Graph("微博转发关系图", width=1200, height=600) graph.add("", nodes, links, categories, label_pos="right", repulsion=50, is_legend_show=False, line_curve=0.2, label_text_color=None) graph.show_config() graph.render()
}, { "name": "结点6", "symbolSize": 20 }, { "name": "结点7", "symbolSize": 20 }, { "name": "结点8", "symbolSize": 10 }, ] links = [] for i in nodes: for j in nodes: links.append({"source": i.get("name"), "target": j.get("name")}) graph = Graph("关系图-力引导布局示例") #width=1200,height=600) graph.add("", nodes, links, is_label_show=True, repulsion=8000, graph_layout="circular", label_pos="right") graph.render() data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] print(data)
"name": "宿州学院", "symbolSize": 40 }, { "name": "安徽大学", "symbolSize": 50 }, { "name": "铜陵学院", "symbolSize": 40 }, { "name": "中国科技大学", "symbolSize": 30 }, { "name": "安徽理工大学", "symbolSize": 20 }] links = [] for i in nodes: for j in nodes: links.append({"source": i.get('name'), "target": j.get('name')}) graph = Graph("关系图-环形布局示例") graph.add("", nodes, links, is_label_show=True, repulsion=8000, layout='circular', label_text_color='#000', line_curve=0.05) graph.show_config() graph.render(r"Graph(关系图).html")
# coding=utf8 """ 本示例使用 networkx 库构建复杂、更人性化的的关系图 安装 pip install networkx 参考 https://networkx.github.io/ """ from __future__ import unicode_literals import networkx as nx from networkx.readwrite import json_graph from pyecharts import Graph g = nx.Graph() g.add_node('G1', name='Gateway 1') g.add_node('N2', name='Node 2') g.add_node('N3', name='Node 3') g.add_edge('G1', 'N2') g.add_edge('G1', 'N3') g_data = json_graph.node_link_data(g) eg = Graph('设备最新拓扑图') eg.add('Devices', nodes=g_data['nodes'], links=g_data['links']) eg.render()
"name": "结点4" }, { "name": "结点5" }, { "name": "结点6" }, { "name": "结点7" }, { "name": "结点8" }] links = [] for i in nodes: #print 'i----',i for j in nodes: links.append({"source": i.get('name'), "target": j.get('name')}) for x1 in links: print 'x' for x2 in x1: print '%s ---- %s' % (x2, x1[x2]) graph = Graph("关系图-环形布局示例") graph.add("", nodes, links, is_label_show=True, graph_repulsion=8000, label_text_color=None) graph.render('graph.html') print 'ok'
print(len(nodes)) print( len( set([links_v[i]['source'] for i in range(len(links_v))] + [links_v[i]['target'] for i in range(len(links_v))]))) print(nodes[:10]) print(links_v[:10]) print('rendering....') title = 'Connections between actors' g = Graph(title, title_pos='center') g.add('', nodes, links_v, graph_edge_length=[10, 100], graph_gravity=0.1) g.render(title + '.html') #----------------------------------------------------------------------- from pyecharts import Graph import itertools dfv = df.loc[df['title_year'] > 2011, :] connection = ['actor_' + str(i + 1) + '_name' for i in range(3)] fl = ['actor_' + str(i + 1) + '_facebook_likes' for i in range(3)] df_fl = pd.DataFrame({'actor': [], 'FL': []}) for i in range(3): df0 = pd.DataFrame({ 'actor': dfv.loc[:, connection[i]],
"symbolSize": 30 }, { "name": "结点4", "symbolSize": 40 }, { "name": "结点5", "symbolSize": 50 }, { "name": "结点6", "symbolSize": 40 }, { "name": "结点7", "symbolSize": 30 }, { "name": "结点8", "symbolSize": 20 }] links = [] for i in nodes: for j in nodes: links.append({"source": i.get('name'), "target": j.get('name')}) graph = Graph("关系图-环形布局示例") graph.add("", nodes, links, is_label_show=True, graph_repulsion=8000, graph_layout='circular', label_text_color=None) graph.render("./img/关系图.html")
def plot_chnx(ch1=None, ch2=None, check_code=None): # df = pd.read_csv(DATA_URL + '/chinese_characters.csv') df = pd.read_csv(DATA_URL + '/fanti.edgelist', sep='\t', header=None, names=['ch1', 'ch2']) df.drop_duplicates(keep='first', inplace=True) if check_code in [1, 5]: df = df.loc[(df['ch1'] == ch1) | (df['ch2'] == ch1)] nodes = [{ "name": ch, "symbolSize": 10, "itemStyle": { "normal": { "color": 'red' } } } for ch in set(df['ch1'].unique()) | set(df['ch2'].unique())] links = [{ "source": value[0], "target": value[1], "lineStyle": { "normal": { "color": 'green' } } } for value in df.values] graph = Graph("汉字-关系图", width=1200, height=600) graph.add("", nodes, links, repulsion=80, layout="force", graph_edge_length=150, is_roam=True, is_label_show=True, is_legend_show=True, draggable=True, lineStyle='-.', graph_edge_symbol=['circle', 'arrow']) graph.render() elif check_code == 4: df = df.loc[(df['ch1'] == ch1) | (df['ch2'] == ch1) | (df['ch1'] == ch2) | (df['ch2'] == ch2)] df1 = df.loc[((df['ch1'] == ch1) & (df['ch2'] != ch2)) | ((df['ch2'] == ch1) & (df['ch1'] != ch2))] df2 = df.loc[((df['ch1'] == ch2) & (df['ch2'] != ch1)) | ((df['ch2'] == ch2) & (df['ch1'] != ch1))] df3 = df.loc[((df['ch1'] == ch1) & (df['ch2'] == ch2)) | ((df['ch2'] == ch1) & (df['ch1'] == ch2))] nodes = [{ "name": ch, "symbolSize": 10, "itemStyle": { "normal": { "color": 'red' } } } for ch in set(df1['ch1'].unique()) | set(df1['ch2'].unique())] nodes += [{ "name": ch, "symbolSize": 10, "itemStyle": { "normal": { "color": 'blue' } } } for ch in set(df2['ch1'].unique()) | set(df2['ch2'].unique())] links = [{ "source": value[0], "target": value[1], "lineStyle": { "normal": { "color": 'PaleTurquoise' } } } for value in df1.values] links += [{ "source": value[0], "target": value[1], "lineStyle": { "normal": { "color": 'gray' } } } for value in df2.values] links += [{ "source": value[0], "target": value[1], "lineStyle": { "normal": { "color": 'Teal' } } } for value in df3.values] graph = Graph("汉字-关系图", width=1200, height=600) graph.add("", nodes, links, repulsion=80, layout="force", graph_edge_length=150, is_roam=True, is_label_show=True, is_legend_show=True, draggable=True, lineStyle='-.', graph_edge_symbol=['circle', 'arrow']) graph.render() elif check_code == 6: df = df.loc[(df['ch1'] == ch2) | (df['ch2'] == ch2)] nodes = [{ "name": ch, "symbolSize": 10, "itemStyle": { "normal": { "color": 'red' } } } for ch in set(df['ch1'].unique()) | set(df['ch2'].unique())] links = [{ "source": value[0], "target": value[1], "lineStyle": { "normal": { "color": 'green' } } } for value in df.values] graph = Graph("汉字-关系图", width=1200, height=600) graph.add("", nodes, links, repulsion=80, layout="force", graph_edge_length=150, is_roam=True, is_label_show=True, is_legend_show=True, draggable=True, lineStyle='-.', graph_edge_symbol=['circle', 'arrow']) graph.render() context = dict(myechart=graph.render_embed(), host='/static/js', script_list=graph.get_js_dependencies()) context.update(network_info(ch1, ch2)) return context
def drawGraphRelation2(): from pyecharts import Graph nodes = [{ "name": "rule1", "symbolSize": 20 }, { "name": "rule2", "symbolSize": 20 }, { "name": "rule3", "symbolSize": 20 }, { "name": "rule4", "symbolSize": 20 }, { "name": "rule5", "symbolSize": 20 }, { "name": "rule6", "symbolSize": 20 }, { "name": "rule7", "symbolSize": 20 }, { "name": "rule8", "symbolSize": 20 }, { "name": "rule9", "symbolSize": 20 }, { "name": "rule1_1", "symbolSize": 10 }, { "name": "rule1_2", "symbolSize": 10 }, { "name": "rule1_3", "symbolSize": 10 }, { "name": "rule2_1", "symbolSize": 10 }, { "name": "rule2_2", "symbolSize": 10 }, { "name": "rule2_1_1", "symbolSize": 10 }, { "name": "rule2_1_2", "symbolSize": 10 }, { "name": "rule2_1_3", "symbolSize": 10 }, { "name": "rule2_2_1", "symbolSize": 10 }, { "name": "rule3_1", "symbolSize": 10 }, { "name": "rule3_2", "symbolSize": 10 }, { "name": "rule0", "symbolSize": 30 }] links = [] links.append({"source": "rule0", "target": "rule1"}) links.append({"source": "rule0", "target": "rule2"}) links.append({"source": "rule0", "target": "rule3"}) links.append({"source": "rule0", "target": "rule4"}) links.append({"source": "rule0", "target": "rule5"}) links.append({"source": "rule0", "target": "rule6"}) links.append({"source": "rule0", "target": "rule7"}) links.append({"source": "rule0", "target": "rule8"}) links.append({"source": "rule0", "target": "rule9"}) links.append({"source": "rule1", "target": "rule1_1"}) links.append({"source": "rule1", "target": "rule1_2"}) links.append({"source": "rule1", "target": "rule1_3"}) links.append({"source": "rule2", "target": "rule2_1"}) links.append({"source": "rule2", "target": "rule2_2"}) links.append({"source": "rule2_1", "target": "rule2_1_1"}) links.append({"source": "rule2_1", "target": "rule2_1_2"}) links.append({"source": "rule2_1", "target": "rule2_2_1"}) links.append({"source": "rule3", "target": "rule3_1"}) links.append({"source": "rule3", "target": "rule3_2"}) graph = Graph("Demo of Pyechart - Rule relationship") graph.add( "", nodes, links, is_label_show=True, #graph_repulsion=8000, graph_repulsion=80000, line_curve=0.2, graph_layout="circular", label_text_color=None, ) graph.render()
# -*- coding: utf-8 -*- """ Created on Thu Aug 10 15:23:34 2017 @author: 17549 """ from pyecharts import Graph import json with open("..\json\weibo.json", "r", encoding="utf-8") as f: j = json.load(f) nodes, links, categorise, cont, mid, userl = j graph = Graph("微博转发关系图", width=1200, height=600) graph.add("", nodes, links, categories, label_pos="right", repulsion=50, is_legend_show=False, line_curve=0.2, label_text_color=None) graph.show_config() graph.render(r"E:\6_关系图-力应布局.html")
}, { "name": "结点6", "symbolSize": 40 }, { "name": "结点7", "symbolSize": 30 }, { "name": "结点8", "symbolSize": 20 }] links = [] for i in nodes: for j in nodes: links.append({"source": i.get('name'), "target": j.get('name')}) graph = Graph("关系图-环形布局示例") graph.add("", nodes, links, is_label_show=True, graph_repulsion=800000, graph_layout='circular', label_text_color=None, is_focusnode=True, is_roam=True, is_rotatelabel=False, layout="force", edge_length=100, gravity=0.001, repulsion=100) graph.render("graph.html")
"name": "结点2", "symbolSize": 20 }, { "name": "结点3", "symbolSize": 30 }, { "name": "结点4", "symbolSize": 40 }, { "name": "结点5", "symbolSize": 50 }, { "name": "结点6", "symbolSize": 40 }, { "name": "结点7", "symbolSize": 30 }, { "name": "结点8", "symbolSize": 20 }] links = [] for i in nodes: for j in nodes: links.append({"source": i.get("name"), "target": j.get('name')}) graph = Graph("关系图-力引导布局示例") graph.add("test", nodes, links, graph_repulsion=8000, is_more_utils=True) graph.render(path="graph.html")
from pyecharts import Graph import pandas as pd sim_frame = pd.read_csv('./data/philosophy.csv', index_col=0, encoding='utf8') names = sim_frame.index sim_frame = sim_frame ** 0.25 graph = Graph('哲♂学关系图', width=1000, height=1000) nodes = [{'name': name, 'symbolSize': 30, 'value': 1} for name in names] links = [{ 'source': i, 'target': j, 'value': sim_frame.loc[i, j] } for i in names for j in names if i < j] graph.add( '', nodes, links, is_focusnode=True, is_roam=True, is_rotatelabel=False, layout="force", graph_edge_length=list(range(100, 601, 100)), graph_gravity=0.1, graph_repulsion=8000, is_label_show=True, is_legend_show=True, line_curve=0, ) graph.render('./data/philosophy.html')