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