我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用networkx.write_dot()。
def write_dot(self, dotfile): """ Outputs the word graph in dot format in the specified file. """ nx.write_dot(self.graph, dotfile) #-B-----------------------------------------------------------------------B-
def export_memory_graph(filename, graph): nx.write_dot(graph, '{}.dot'.format(filename)) logging.debug('{}.dot created'.format(filename))
def main(): func_list = parse.parse(open(sys.argv[1]).read()) G = foo(func_list) #G = callgraph(func_list) nx.write_dot(G,"G.dot") #H = nx.dfs_tree(G,'solver') #nx.write_dot(H,"H.dot") #print nx.topological_sort(H)
def draw_graph(mst, mst_a, mol_names, dir_names, method): import networkx as nx G = nx.from_scipy_sparse_matrix(mst) if method == 'mcs': corr = 1 else: corr = 0 for i, j in zip(mst.nonzero()[0], mst.nonzero()[1]): G.edge[i][j]['label'] = '%.1f' % (mst_a[i][j] - corr) G.edge[i][j]['len'] = '3.0' for n in G.nodes(): G.node[n]['shape'] = 'box' G.node[n]['label'] = ('<' '<table border="0" cellspacing="-20" cellborder="0">' '<tr><td><img src="%s"/></td></tr>' '<tr><td bgcolor="#F0F0F0">%s</td></tr>' '</table>>' % (os.path.join(dir_names[n], mol_names[n] + os.extsep + 'svg'), mol_names[n]) ) print('Writing networkx graph pickle file %s...' % GPICKLE_FILE) nx.write_gpickle(G, GPICKLE_FILE) print('Writing DOT file %s...' % DOT_FILE) nx.write_dot(G, DOT_FILE)
def extract_diff_graph(graph, diff): diff_graph = graph.copy() diff_graph.root_nodes = list() # pnodes = collections.defaultdict(set) # for m in diff[0] | diff[2]: # for n in diff_graph.nodes(): # if nx.has_path(diff_graph, n, m): # pnodes[m].add(n) # # nodes = set.union(*pnodes.values()) nodes = set() logging.debug('Searching on-paths nodes...') for m in graph.root_nodes: for i in diff[0] | diff[2]: if m == i: nodes.add(m) try: nodes.update(*list(search_paths(diff_graph, m, i))) except: pass if m in nodes: diff_graph.root_nodes.append(m) logging.debug('Removing nodes off-path...') for n in diff_graph.nodes()[:]: if n not in nodes: diff_graph.remove_node(n) logging.debug('Setting node colors...') for n in diff_graph.nodes(): diff_graph.node[n]['color'] = 'turquoise' for n in diff[0]: diff_graph.node[n]['color'] = 'red' if isinstance(n, Stack): diff_graph.node[n]['color'] = 'deeppink' for n in diff[2]: diff_graph.node[n]['color'] = 'green' logging.debug('Exporting diff_graph.dot...') nx.write_dot(diff_graph, 'diff_graph.dot') return diff_graph # internal classes # internal functions