-
-
randomly generate a set chart, with the path attribute, the figure size 1*1, find the closest node from the center [0.5, 0.5], and follow the path staining.
networkx Examples? Drawing? Random Geometric Graph
<pre name= "code" class= "Python" > #coding: Utf-8import networkx as Nximport Matplotlib.pyplot as Pltg=nx.random_ Geometric_graph (200,0.125) # position is stored as node attribute data for Random_geometric_graphpos=nx.get_node_ Attributes (G, ' pos ') # Find node near center (0.5,0.5) finds the center node and asks the nearest node, set to Ncenterdmin=1ncenter=0for N in Pos:x,y=pos[n] D = (x-0.5) **2+ (y-0.5) **2 if d<dmin:ncenter=n dmin=d# color by path length from node near center color is set to red, process Degrees <span style= "font-family:arial, Helvetica, Sans-serif;" > by Distance Center point path length dyeing </span>p=nx.single_source_shortest_path_length (g,ncenter) plt.figure (figsize= (8,8)) Nx.draw_networkx_edges (g,pos,nodelist=[ncenter],alpha=0.4) nx.draw_networkx_nodes (G,pos,nodelist=p.keys (), Node_size=80, Node_color=p.values (), Cmap=plt.cm.reds_r) Plt.xlim ( -0.05,1 . Plt.ylim ( -0.05,1.05) plt.axis (' Off ') plt.savefig (' Random_geometric_graph.png ') plt.show ()
Copyright NOTICE: Welcome reprint, Reprint please indicate the source http://blog.csdn.net/ztf312/
Python-networkx: Drawing random geometry, finding the center node and dyeing by path length