wsngenerator.py 文件源码

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

项目:rpl-attacks 作者: dhondta 项目源码 文件源码
def draw_wsn(motes=None, algo='quadrants', **kwargs):
    """
    This function allows to draw the list of motes generated with one of the WSN generation functions hereafter.

    :param motes: a list of motes as output by one of the WSN generation functions hereafter
    """
    assert algo in __all__
    import networkx as nx
    from matplotlib import pyplot as plt
    motes = motes or eval(algo)(**kwargs)
    wsn = nx.Graph()
    for mote in motes:
        wsn.add_node(mote['id'])
    pos = {m['id']: (m['x'], m['y']) for m in motes}
    col = ['green'] + (len(motes) - 2) * ['blue'] + ['red']
    nx.draw(wsn, pos, node_color=col)
    plt.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号