def draw_garph_3d(node): """ Draw uni-directional or bi-directional graph in 3D space. """ nodes = serializer.graph_to_nodes_set(node) edges = [] for node in nodes: for neighbor in node.neighbors: edges.append((str(node.uuid), str(neighbor.uuid))) jgraph.draw(edges)
# In[26]: import networkx as nx get_ipython().magic('matplotlib inline') results = get_ipython().magic( 'cypher MATCH p = (:Person)-[:LIKES]->(:Drink) RETURN p') g = results.get_graph() nx.draw(g) # In[27]: g.nodes(data=True) # In[28]: nx.degree(g) # # jgraph # # `jgraph` will plot tuple lists as 3D graphs. # In[29]: import jgraph jgraph.draw([(1, 2), (2, 3), (3, 4), (4, 1), (4, 5), (5, 2)])
import jgraph graph = {'nodes': {'ft_traceroute': {}, '42_Commandements': {'color': 16755370, 'size': 2.0}, 'ft_ality': {}, 'ft_ls': {}, 'ft_ping': {}, 'RT': {}, 'mod1': {}, 'H42N42': {}, 'ft_script': {}, 'In_the_Shadows': {}, '21sh': {}, 'RainFall': {}, 'Filit': {'color': 10624845, 'size': 1.0}, 'lem_in': {'color': 10624845, 'size': 1.0}, 'Woody_Woodpacker': {}, 'Process_and_Memory': {}, 'Filesystem': {}, 'cloud_1': {}, 'Abstract_VM': {}, 'little_penguin_1': {}, 'Gomoku': {}, 'libft': {'color': 10624845, 'size': 1.0}, 'Piscine_Ruby_on_Rails': {}, 'Corewar': {'color': 10624845, 'size': 1.0}, 'Rushes': {}, 'ft_p': {}, 'Scop': {}, 'libftASM': {}, 'ft_hangouts': {}, 'Expert_System': {}, 'Hypertube': {}, 'KrpSim': {}, 'Corewar_Championship': {}, 'Savoir_Relier': {}, 'Filer': {}, 'Piscine_OCaml': {}, 'Music_Room': {}, 'Malloc': {}, 'ft_turing': {}, 'Zappy': {}, 'Camagru': {}, 'Famine': {}, 'Piscine_Swift_iOS': {}, 'Taskmaster': {}, 'ComputorV1': {}, 'Red_Tetris': {}, 'Matt_Daemon': {}, 'Open_Project_II': {}, 'Dr_Quine': {}, 'lem_ipc': {}, 'Final_Internship': {}, 'Push_swap': {'color': 10624845, 'size': 1.0}, 'Darkly': {}, 'First_Internship': {'color': 10624845, 'size': 1.0}, 'Root_me_|_Cracking': {}, 'Nm_otool': {}, 'Nibbler': {}, 'ft_printf': {'color': 10624845, 'size': 1.0}, 'Piscine_CPP': {}, 'Piscine_Reloaded': {'color': 10624845, 'size': 1.0}, 'Docker': {}, 'Piscine_Unity': {}, 'ft_linear_regression': {}, 'FdF': {}, 'XV': {}, 'Bomberman': {}, 'Wolf3d': {}, 'Root_me_|_App_Systeme': {}, 'HumanGl': {}, 'Matcha': {}, 'Snow_Crash': {}, 'Swifty_Companion': {}, '42run': {}, 'ft_nmap': {}, 'ft_select': {}, 'RTv1': {}, 'GBmu': {}, 'C_Exam___Beginner': {}, 'Open_Project_I': {}, 'Rubik': {}, "Fract'ol": {}, 'Piscine_Python_Django': {}, 'Part_time': {}, 'Particle_System': {}, '42sh': {}, 'Philosophers': {}, 'N_puzzle': {}, 'Piscine_PHP': {}, 'Get_Next_line': {'color': 10624845, 'size': 1.0}, 'Swifty_Proteins': {}, 'Drivers_and_Interrupts': {}, 'IRC': {}, 'strace': {}, 'roger_skyline_2': {}, 'roger_skyline_1': {}, 'KFS_2': {}, 'KFS_3': {}, 'KFS_1': {}, 'ft_linux': {}, 'KFS_4': {'color': 4920919, 'size': 2.0}, 'minishel': {}, 'Friends_with_Benefits': {}}, 'edges': [{'source': '42_Commandements', 'target': 'Piscine_Reloaded'}, {'source': 'Piscine_Reloaded', 'target': 'libft'}, {'source': 'libft', 'target': 'Filit'}, {'source': 'Filit', 'target': 'Get_Next_line'}, {'source': 'Get_Next_line', 'target': 'ft_printf'}, {'source': 'ft_printf', 'target': 'Push_swap'}, {'source': 'ft_printf', 'target': 'Filer'}, {'source': 'Push_swap', 'target': 'lem_in'}, {'source': 'Filer', 'target': 'lem_in'}, {'source': 'lem_in', 'target': 'Corewar'}, {'source': 'lem_in', 'target': 'mod1'}, {'source': 'Corewar', 'target': 'First_Internship'}, {'source': 'Corewar', 'target': 'Corewar_Championship'}, {'source': 'Get_Next_line', 'target': 'FdF'}, {'source': 'FdF', 'target': "Fract'ol"}, {'source': "Fract'ol", 'target': 'Wolf3d'}, {'source': "Fract'ol", 'target': 'RTv1'}, {'source': 'RTv1', 'target': 'RT'}, {'source': 'Wolf3d', 'target': 'RT'}, {'source': 'RT', 'target': 'First_Internship'}, {'source': 'Get_Next_line', 'target': 'ft_ls'}, {'source': 'ft_ls', 'target': 'minishel'}, {'source': 'minishel', 'target': 'ft_select'}, {'source': 'minishel', 'target': '21sh'}, {'source': '21sh', 'target': 'Taskmaster'}, {'source': '21sh', 'target': '42sh'}, {'source': '42sh', 'target': 'First_Internship'}, {'source': 'Piscine_PHP', 'target': 'Camagru'}, {'source': 'Camagru', 'target': 'Matcha'}, {'source': 'Matcha', 'target': 'Hypertube'}, {'source': 'Matcha', 'target': 'First_Internship'}, {'source': 'First_Internship', 'target': 'Friends_with_Benefits'}, {'source': 'First_Internship', 'target': 'Darkly'}, {'source': 'First_Internship', 'target': 'Red_Tetris'}, {'source': 'First_Internship', 'target': 'ComputorV1'}, {'source': 'First_Internship', 'target': 'N_puzzle'}, {'source': 'First_Internship', 'target': 'Expert_System'}, {'source': 'Expert_System', 'target': 'Gomoku'}, {'source': 'Expert_System', 'target': 'ft_linear_regression'}, {'source': 'Expert_System', 'target': 'KrpSim'}, {'source': 'Expert_System', 'target': 'Rubik'}, {'source': 'N_puzzle', 'target': 'Rubik'}, {'source': 'N_puzzle', 'target': 'Gomoku'}, {'source': 'N_puzzle', 'target': 'ft_linear_regression'}, {'source': 'N_puzzle', 'target': 'KrpSim'}, {'source': 'First_Internship', 'target': 'Scop'}, {'source': 'Scop', 'target': '42run'}, {'source': 'Scop', 'target': 'HumanGl'}, {'source': 'Scop', 'target': 'Particle_System'}, {'source': 'First_Internship', 'target': 'Malloc'}, {'source': 'Malloc', 'target': 'Philosophers'}, {'source': 'Malloc', 'target': 'ft_script'}, {'source': 'Malloc', 'target': 'Nm_otool'}, {'source': 'Nm_otool', 'target': 'ft_p'}, {'source': 'Nm_otool', 'target': 'IRC'}, {'source': 'IRC', 'target': 'Zappy'}, {'source': 'Nm_otool', 'target': 'Zappy'}, {'source': 'IRC', 'target': 'Matt_Daemon'}, {'source': 'Nm_otool', 'target': 'Matt_Daemon'}, {'source': 'IRC', 'target': 'lem_ipc'}, {'source': 'Nm_otool', 'target': 'lem_ipc'}, {'source': 'IRC', 'target': 'ft_ping'}, {'source': 'Nm_otool', 'target': 'ft_ping'}, {'source': 'ft_ping', 'target': 'ft_traceroute'}, {'source': 'ft_traceroute', 'target': 'ft_nmap'}, {'source': 'Nm_otool', 'target': 'libftASM'}, {'source': 'libftASM', 'target': 'strace'}, {'source': 'libftASM', 'target': 'GBmu'}, {'source': 'libftASM', 'target': 'ft_linux'}, {'source': 'ft_linux', 'target': 'little_penguin_1'}, {'source': 'little_penguin_1', 'target': 'Process_and_Memory'}, {'source': 'Process_and_Memory', 'target': 'Drivers_and_Interrupts'}, {'source': 'Drivers_and_Interrupts', 'target': 'Filesystem'}, {'source': 'Filesystem', 'target': 'KFS_1'}, {'source': 'KFS_1', 'target': 'KFS_2'}, {'source': 'KFS_2', 'target': 'KFS_3'}, {'source': 'KFS_3', 'target': 'KFS_4'}, {'source': 'libftASM', 'target': 'Snow_Crash'}, {'source': 'Snow_Crash', 'target': 'RainFall'}, {'source': 'libftASM', 'target': 'Root_me_|_App_Systeme'}, {'source': 'Root_me_|_App_Systeme', 'target': 'Root_me_|_Cracking'}, {'source': 'Famine', 'target': 'Woody_Woodpacker'}, {'source': 'Woody_Woodpacker', 'target': 'Nm_otool'}, {'source': 'Famine', 'target': 'libftASM'}, {'source': 'First_Internship', 'target': 'Dr_Quine'}, {'source': 'First_Internship', 'target': 'Piscine_Python_Django'}, {'source': 'First_Internship', 'target': 'Piscine_Ruby_on_Rails'}, {'source': 'First_Internship', 'target': 'Docker'}, {'source': 'First_Internship', 'target': 'Music_Room'}, {'source': 'First_Internship', 'target': 'Piscine_OCaml'}, {'source': 'Piscine_OCaml', 'target': 'H42N42'}, {'source': 'Piscine_OCaml', 'target': 'ft_turing'}, {'source': 'Piscine_OCaml', 'target': 'ft_ality'}, {'source': 'First_Internship', 'target': 'Piscine_Swift_iOS'}, {'source': 'First_Internship', 'target': 'Piscine_CPP'}, {'source': 'Piscine_CPP', 'target': 'Piscine_Unity'}, {'source': 'Swifty_Companion', 'target': 'Piscine_CPP'}, {'source': 'Swifty_Companion', 'target': 'Piscine_Swift_iOS'}, {'source': 'Swifty_Proteins', 'target': 'Swifty_Companion'}, {'source': 'Piscine_CPP', 'target': 'ft_hangouts'}, {'source': 'Abstract_VM', 'target': 'Piscine_CPP'}, {'source': 'Nibbler', 'target': 'Abstract_VM'}, {'source': 'Bomberman', 'target': 'Abstract_VM'}, {'source': 'Piscine_Unity', 'target': 'In_the_Shadows'}, {'source': 'In_the_Shadows', 'target': 'XV'}, {'source': 'Open_Project_I', 'target': 'First_Internship'}, {'source': 'Open_Project_II', 'target': 'First_Internship'}, {'source': 'First_Internship', 'target': 'cloud_1'}, {'source': 'First_Internship', 'target': 'roger_skyline_1'}, {'source': 'roger_skyline_1', 'target': 'roger_skyline_2'}]} jgraph.draw(graph, z=200, size=(800, 600), directed= False, shader= "basic")
def plot_(Name, data, b_id_to_names, b_id_to_sex): print('starting plot creating') N = len(data['nodes']) L = len(data['links']) Edges = [(data['links'][k]['source'], data['links'][k]['target']) for k in range(L)] display(HTML(ig.draw(Edges, directed=False))) labels = [] group = [] size_ = [] for node in data['nodes']: labels.append(b_id_to_names[node['name']]) group.append(b_id_to_sex[node['name']]) size_.append(node['size']) layt = ig.generate(Edges) Xn = [layt['nodes'][k]['location'][0] for k in range(N)] # x-coordinates of nodes Yn = [layt['nodes'][k]['location'][1] for k in range(N)] # y-coordinates Zn = [layt['nodes'][k]['location'][2] for k in range(N)] # z-coordinates Xe = [] Ye = [] Ze = [] for e in Edges: Xe += [ layt['nodes'][e[0]]['location'][0], layt['nodes'][e[1]]['location'][0], None ] # x-coordinates of edge ends Ye += [ layt['nodes'][e[0]]['location'][1], layt['nodes'][e[1]]['location'][1], None ] Ze += [ layt['nodes'][e[0]]['location'][2], layt['nodes'][e[1]]['location'][2], None ] trace1 = go.Scatter3d(x=Xe, y=Ye, z=Ze, mode='lines', line=dict(color='rgb(125,125,125)', width=1), hoverinfo='none') trace2 = go.Scatter3d(x=Xn, y=Yn, z=Zn, mode='markers+text', name='actors', marker=dict(symbol='circle', size=size_, color=group, colorscale='Viridis', line=dict(color='rgb(50,50,50)', width=0.5)), text=labels, hoverinfo='text') axis = dict(showbackground=False, showline=False, zeroline=False, showgrid=False, showticklabels=False, title='') layout = go.Layout( title="Мои друзья", width=1000, height=1000, showlegend=False, scene=dict( xaxis=dict(axis), yaxis=dict(axis), zaxis=dict(axis), ), margin=dict(t=100), hovermode='closest', ) data = [trace1, trace2] fig = go.FigureWidget(data=data, layout=layout) py.plot(fig, filename=Name + '_Friends.html')
nodes[i]['color'] = nodes[i]['node_color'].replace('#', '0x') nodes[i].pop('node_color', None) nodes[i].pop('node_label', None) dict_nodes[new_key] = nodes[i] new_edges = [] for i in range(len(edges)): temp = edges[i] temp['source'] = str(temp['source_id']) temp.pop('source_id', None) temp['target'] = str(temp['target_id']) temp.pop('target_id', None) temp['size'] = str(temp['weights']) temp.pop('weights', None) new_edges.append(temp) graph = {'nodes': dict_nodes, 'edges': new_edges} jgraph.draw(graph, size=(1000, 800), node_size=2.0, edge_size=0.1, shader='toon')
print("Vertrixes: ", vertrixes) print("Edges: ", edges) print("N_Vertrixes: ", len(vertrixes)) print("N_Edges: ", len(edges)) print("Jvertrixes:", jvertrixes) print("Jedges:", jedges) return { "edges_array": edges, "vertrix_array": vertrixes, "nodes": jvertrixes, "edges": jedges } for root, dirs, files in os.walk(paperdirectory, topdown=False): for name in files: if "-deep.json" in name: with open(paperdirectory + "/" + name) as f: d = json.load(f) data.append(d) gf = graphPapers(data) import jgraph jgraph.draw(gf) # with open(paperdirectory+'/cross-ref-jgraph.json', 'w') as outfile: # json.dump(gf, outfile, indent=4)