Python-networkx: Drawing random geometry, finding the center node and dyeing by path length

Source: Internet
Author: User

        • 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.