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)
评论列表
文章目录