为networkx中的步行边缘着色
|
我已经编写了一个简单的代码,使用networkx库在给定的图形G中生成随机游动。现在,当我进行游动时,我希望使用matplotlib对边缘进行着色和绘制。
例如:假设我正在从连接边缘从节点1到节点2行走,我希望该边缘的颜色与其余边缘不同。
这是代码:
def unweighted_random_walk(starting_point,ending_point, graph):
\'\'\'
starting_point: String that represents the starting point in the graph
ending_point: String that represents the ending point in the graph
graph: A NetworkX Graph object
\'\'\'
##Begin the random walk
current_point=starting_point
#current_node=graph[current_point]
current_point_neighors=graph.neighbors(current_point)
hitting_time=0
#Determine the hitting time to get to an arbitrary neighbor of the
#starting point
while current_point!=ending_point:
#pick one of the edges out of the starting_node with equal probs
possible_destination=current_point_neighbors[random.randint(0,current_point_neighors)]
current_point=possible_destination
current_point_neighbors=graph.neighbors(current_point)
hitting_time+=1
return hitting_time
没有找到相关结果
已邀请:
2 个回复
炉挤仙挟
稀瓣囊