def draw_overlaid_graphs(original, new_graphs, print_text=False):
"""
Draws the new_graphs as graphs overlaid on the original topology
:type new_graphs: list[nx.Graph]
"""
import matplotlib.pyplot as plt
layout = nx.spring_layout(original)
nx.draw_networkx(original, pos=layout)
# want to overlay edges in different colors and progressively thinner
# so that we can see what edges are in a tree
line_colors = 'rbgycm'
line_width = 2.0 ** (min(len(new_graphs), len(line_colors)) - 1) # use this for visualising on screen
# line_width = 3.0 ** (min(len(new_graphs), len(line_colors)) - 1) # use this for generating diagrams
for i, g in enumerate(new_graphs):
if print_text:
log.info(nx.info(g))
log.info("edges:", list(g.edges()))
nx.draw_networkx(g, pos=layout, edge_color=line_colors[i % len(line_colors)], width=line_width)
# advance to next line width
line_width /= 1.7 # use this for visualising on screen
# line_width /= 2.0 # use this for generating diagrams
plt.show()
评论列表
文章目录