我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用networkx.fruchterman_reingold_layout()。
def save(self, path='out.png'): import networkx import matplotlib.pyplot as plt pos = networkx.spring_layout(self.graph, iterations=500) # pos = networkx.spectral_layout(self.graph) # pos = networkx.shell_layout(self.graph) # pos = networkx.fruchterman_reingold_layout(self.graph) nodelist = list(range(self.num_rooms)) networkx.draw_networkx_nodes(self.graph, pos, nodelist=nodelist) edgelist = sorted(self.edges - self.secret_edges) secret = sorted(self.secret_edges) networkx.draw_networkx_edges(self.graph, pos, edgelist=edgelist, edge_color='k') networkx.draw_networkx_edges(self.graph, pos, edgelist=secret, edge_color='r') networkx.draw_networkx_labels(self.graph, pos, self.labels) plt.savefig(path)
def debug_instance(instance_wf): print '*' * 20 print instance_wf.graph.nodes(data=False) print '*' * 21 print instance_wf.graph.edges() print '*' * 22 print instance_wf.graph.is_multigraph() print '*' * 23 print instance_wf.graph.number_of_edges() print '*' * 24 print instance_wf.sorted_tasks print '*' * 25 test = instance_wf.graph.reverse() print test.edges() print '*' * 26 print instance_wf.graph.in_degree() print instance_wf.check_in_degree_edges() print '*' * 27 print instance_wf.graph.out_degree() print instance_wf.check_out_degree_edges() print '*' * 28 x = instance_wf.get_operations()[0] print x['ports'] # print instance_wf.get_ports_from_operation_tasks('') # Show image # pos = nx.spring_layout(instance_wf.graph) # pos = nx.fruchterman_reingold_layout(instance_wf.graph) # nx.draw(instance_wf.graph, pos, node_color='#004a7b', node_size=2000, # edge_color='#555555', width=1.5, edge_cmap=None, # with_labels=True, style='dashed', # label_pos=50.3, alpha=1, arrows=True, node_shape='s', # font_size=8, # font_color='#FFFFFF') # plt.show() # plt.savefig(filename, dpi=300, orientation='landscape', format=None, # bbox_inches=None, pad_inches=0.1)
def make_graph(list_of_edges): G = nx.Graph() for x in list_of_edges: pair = tuple(x.split("-", 1)) G.add_edge(pair[0], pair[1]) print len(G.edges()) pos=nx.fruchterman_reingold_layout(G) nx.draw(G,pos) plt.show() return len(list_of_edges)
def fruchterman_reingold_layout(self, graph): return nx.fruchterman_reingold_layout(graph,center=[0.5,0.5])