dsm_networkx_algorithms.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:ride 作者: KyleBenson 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号