我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用networkx.draw_circular()。
def draw_circular_graph(graph): graph = nx.cycle_graph(graph.number_of_nodes(), graph) nx.draw_circular(graph) plt.axis('off') plt.show()
def update_net(self, node, edge, direction): plt.figure(1) # self.lg.info("Update net", node, edge, direction) if node: self.net_labels[node] = node if node[0] == "M" and node[1] == "P": if direction == "IN": self.G.add_node(node, behaviour='malicious') else: self.lg.info("simulator: {} removed from graph (MP)".format(node)) self.G.remove_node(node) del self.net_labels[node] elif node[0] == "M": if direction == "IN": self.G.add_node(node, behaviour='monitor') else: self.G.remove_node(node) del self.net_labels[node] else: if direction == "IN": self.G.add_node(node, behaviour='peer') else: self.G.remove_node(node) del self.net_labels[node] else: if edge[0] in self.G.nodes() and edge[1] in self.G.nodes(): if direction == "IN": self.G.add_edge(*edge, color='#000000') else: self.G.add_edge(*edge, color='r') self.net_figure.clf() edges = self.G.edges() edge_color = [self.G[u][v]['color'] for u, v in edges] node_color = [self.color_map[self.G.node[node]['behaviour']]for node in self.G] self.net_figure.suptitle("Overlay Network of the Team", size=16) nx.draw_circular(self.G, node_color=node_color, node_size=400, edge_color=edge_color, labels=self.net_labels, font_size=10, font_weight='bold') self.net_figure.canvas.draw()