{"id":444,"date":"2021-02-28T21:06:12","date_gmt":"2021-02-28T15:06:12","guid":{"rendered":"http:\/\/www.jichangqing.net\/wordpress\/?p=444"},"modified":"2021-02-28T21:06:12","modified_gmt":"2021-02-28T15:06:12","slug":"networkx%e7%94%bb%e5%9b%be%e6%97%b6%e6%98%be%e7%a4%ba%e8%8a%82%e7%82%b9%e5%92%8c%e8%be%b9%e7%9a%84%e5%b1%9e%e6%80%a7","status":"publish","type":"post","link":"http:\/\/www.jichangqing.net\/wordpress\/?p=444","title":{"rendered":"NETWORKX\u753b\u56fe\u65f6\u663e\u793a\u8282\u70b9\u548c\u8fb9\u7684\u5c5e\u6027"},"content":{"rendered":"<div id=\"article_content\" style=\"color: rgba(0, 0, 0, 0.75);\">\n<div class=\"markdown_views prism-atom-one-dark\" style=\"font-weight: inherit; font-style: inherit;\">\n<blockquote style=\"font-weight: inherit; font-style: italic; color: rgba(0, 0, 0, 0.5);\">\n<p style=\"font-style: inherit; color: #999999;\">python\u7684<a style=\"color: #6795b5;\" href=\"https:\/\/networkx.github.io\/\" target=\"_blank\" rel=\"nofollow,noindex\">NetworkX\u5e93<\/a>\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u6784\u5efa\u7f51\u7edc\u62d3\u6251\u5e76\u5b9e\u73b0\u62d3\u6251\u7684\u53ef\u89c6\u5316\uff0c\u8fd9\u5bf9\u4e8e\u7f51\u7edc\u7814\u7a76\uff0c\u65e5\u5e38\u5c55\u793a\u7b49\u90fd\u662f\u5341\u5206\u7684\u65b9\u4fbf\u3002\u4e0d\u8fc7\uff0c\u6211\u53d1\u73b0\u5e76\u6ca1\u6709\u6587\u7ae0\u6bd4\u8f83\u7cfb\u7edf\u7684\u4ecb\u7ecd\u5982\u4f55\u5728\u53ef\u89c6\u5316\u7684\u56fe\u4e2d\u5c55\u793a\u8282\u70b9\u548c\u8fb9\u7684\u5c5e\u6027\uff0c\u4ece\u800c\u8ba9\u56fe\u66f4\u52a0\u7684\u5177\u4f53\uff0c\u76f4\u89c2\u3002\u56e0\u6b64\u5c31\u60f3\u5199\u4e00\u7bc7\u6587\u7ae0\u6765\u6559\u4f1a\u5927\u5bb6\u5982\u4f55\u5728\u56fe\u4e2d\u663e\u793a\u8282\u70b9\u548c\u8fb9\u7684\u5c5e\u6027\u3002<\/p>\n<\/blockquote>\n<h2 style=\"font-weight: bold; font-style: inherit; color: #4f4f4f;\">\u603b\u4f53\u601d\u8def<\/h2>\n<p style=\"font-style: inherit; color: #4f4f4f;\">\u5148\u8bf4\u603b\u4f53\u601d\u8def\uff0c\u60f3\u8981\u5c55\u793a\u8282\u70b9\u548c\u8fb9\u7684\u5c5e\u6027\uff0c\u6211\u4eec\u9700\u8981\u501f\u52a9\u5982\u4e0b\u4e24\u4e2a\u51fd\u6570\uff08\u91cd\u70b9\u5173\u6ce8labels\u53c2\u6570\uff09\uff1a<\/p>\n<pre class=\"prettyprint\" style=\"font-weight: inherit; font-style: inherit; color: #000000;\"><code class=\"has-numbering\" style=\"font-weight: inherit; font-style: inherit; color: #abb2bf;\">draw_networkx_labels(G, pos, labels=a dictionary used to describe what you want to show in node)\r\ndraw_networkx_edge_labels(G, pos, labels=a dictionary used to describe what you want to show in edge)\r\n<\/code><\/pre>\n<ul class=\"pre-numbering\">\n<li style=\"color: #999999;\">1<\/li>\n<li style=\"color: #999999;\">2<\/li>\n<\/ul>\n<p style=\"font-style: inherit; color: #4f4f4f;\">draw_networkx_labels\u4f1a\u5728\u56fe\u4e2d\u7684\u8282\u70b9\u4e0a\u663e\u793a\u4f60\u901a\u8fc7labels\u53c2\u6570\u4f20\u5165\u7684\u6570\u636e\u3002<br \/>\n\u540c\u7406\uff0cdraw_networkx_edge_labels\u5219\u4f1a\u5728\u56fe\u4e2d\u7684\u8fb9\u4e0a\u663e\u793a\u4f60\u901a\u8fc7labels\u53c2\u6570\u4f20\u5165\u7684\u6570\u636e\u3002<\/p>\n<p style=\"font-style: inherit; color: #4f4f4f;\">\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u4e24\u4e2a\u51fd\u6570\u53ea\u663e\u793a\u4e86labels\uff0c\u5e76\u4e0d\u4f1a\u5c06\u70b9\u554a\uff0c\u8fb9\u554a\u663e\u793a\u51fa\u6765\u3002<span style=\"color: red;\">\u6240\u4ee5\uff0c\u4e3a\u4e86\u663e\u793a\u5b8c\u6574\u7684\u62d3\u6251\uff0c\u5728\u8c03\u7528\u4ee5\u4e0a\u4e24\u4e2a\u51fd\u6570\u4e4b\u524d\uff0c\u9700\u8981\u5148\u8c03\u7528draw(G, pos)\u5c06\u57fa\u7840\u7684\u70b9\u8fb9\u62d3\u6251\u5148\u753b\u51fa\u6765\uff0c\u7136\u540e\u518d\u8c03\u7528draw_networkx_labels\u548cdraw_networkx_edge_labels\u6765\u753b\u51fa\u70b9\u7684labels\u548c\u8fb9\u7684labels\u3002<\/span><\/p>\n<p style=\"font-style: inherit; color: #4f4f4f;\">\u6a21\u677f\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"prettyprint\" style=\"font-weight: inherit; font-style: inherit; color: #000000;\"><code class=\"has-numbering\" style=\"font-weight: inherit; font-style: inherit; color: #abb2bf;\">import networkx as nx\r\nimport matplotlib.pyplot as plt\r\n\r\nG = nx.Graph()\r\n\r\n# Write your topology construction logic here\r\n\r\npos = nx.spring_layout(G) #choose a layout from https:\/\/networkx.github.io\/documentation\/latest\/reference\/drawing.html#module-networkx.drawing.layout\r\nnx.draw(G, pos)\r\nnode_labels = {a dictionary contains what you want you show. Key:node_name. Value:text shown in node G.nodes[node_name]}\r\nnx.draw_networkx_labels(G, pos, labels=node_labels)\r\nedge_labels = {a dictionary contains what you want you show. Key:edge. Value:text shown in edge}\r\nnx.draw_networkx_edge_labels(G, pos, labels=edge_labels)\r\nplt.show()\r\n<\/code><\/pre>\n<ul class=\"pre-numbering\">\n<li style=\"color: #999999;\">1<\/li>\n<li style=\"color: #999999;\">2<\/li>\n<li style=\"color: #999999;\">3<\/li>\n<li style=\"color: #999999;\">4<\/li>\n<li style=\"color: #999999;\">5<\/li>\n<li style=\"color: #999999;\">6<\/li>\n<li style=\"color: #999999;\">7<\/li>\n<li style=\"color: #999999;\">8<\/li>\n<li style=\"color: #999999;\">9<\/li>\n<li style=\"color: #999999;\">10<\/li>\n<li style=\"color: #999999;\">11<\/li>\n<li style=\"color: #999999;\">12<\/li>\n<li style=\"color: #999999;\">13<\/li>\n<li style=\"color: #999999;\">14<\/li>\n<\/ul>\n<p style=\"font-style: inherit; color: #4f4f4f;\">\u770b\u5230\u8fd9\uff0c\u4f60\u53ef\u80fd\u8fd8\u4e0d\u662f\u5f88\u660e\u767d\u5230\u5e95\u8be5\u600e\u4e48\u7528\u3002\u4e0d\u8981\u7740\u6025\uff0c\u4e0b\u9762\u6211\u4eec\u901a\u8fc7\u51e0\u4e2a\u4f8b\u5b50\u6765\u5b9e\u6218\u4e00\u4e0b\uff0c\u770b\u5b8c\u8fd9\u51e0\u4e2a\u4f8b\u5b50\uff0c\u4f60\u518d\u56de\u6765\u770b\u4e0a\u9762\u7684\u5185\u5bb9\uff0c\u5c31\u80fd\u5b8c\u5168\u7406\u89e3\u4e86\uff01<\/p>\n<hr \/>\n<h2 style=\"font-weight: bold; font-style: inherit; color: #4f4f4f;\">\u4f8b\u5b501<\/h2>\n<pre class=\"prettyprint\" style=\"font-weight: inherit; font-style: inherit; color: #000000;\"><code class=\"has-numbering\" style=\"font-weight: inherit; font-style: inherit; color: #abb2bf;\">import networkx as nx\r\nimport matplotlib.pyplot as plt\r\n\r\ndef main():\r\n    G = nx.Graph()\r\n    \r\n    #topology construction logic\r\n    G.add_node('s1', desc='I am switch 1')\r\n    G.add_node('s2', desc='I am switch 2')\r\n    G.add_node('s3', desc='I am switch 3')\r\n    G.add_edge('s1','s2', name='edge 0')\r\n    G.add_edge('s1','s3', name='edge 1')\r\n    G.add_edge('s2','s3', name='edge 2')\r\n    \r\n    #draw graph with labels\r\n    pos = nx.spring_layout(G)\r\n    nx.draw(G, pos)\r\n    node_labels = nx.get_node_attributes(G, 'desc')\r\n    nx.draw_networkx_labels(G, pos, labels=node_labels)\r\n    edge_labels = nx.get_edge_attributes(G, 'name')\r\n    nx.draw_networkx_edge_labels(G, pos, labels=edge_labels)\r\n    plt.show()\r\n\r\n\r\nif __name__ == '__main__':\r\n    main()\r\n<\/code><\/pre>\n<ul class=\"pre-numbering\">\n<li style=\"color: #999999;\">1<\/li>\n<li style=\"color: #999999;\">2<\/li>\n<li style=\"color: #999999;\">3<\/li>\n<li style=\"color: #999999;\">4<\/li>\n<li style=\"color: #999999;\">5<\/li>\n<li style=\"color: #999999;\">6<\/li>\n<li style=\"color: #999999;\">7<\/li>\n<li style=\"color: #999999;\">8<\/li>\n<li style=\"color: #999999;\">9<\/li>\n<li style=\"color: #999999;\">10<\/li>\n<li style=\"color: #999999;\">11<\/li>\n<li style=\"color: #999999;\">12<\/li>\n<li style=\"color: #999999;\">13<\/li>\n<li style=\"color: #999999;\">14<\/li>\n<li style=\"color: #999999;\">15<\/li>\n<li style=\"color: #999999;\">16<\/li>\n<li style=\"color: #999999;\">17<\/li>\n<li style=\"color: #999999;\">18<\/li>\n<li style=\"color: #999999;\">19<\/li>\n<li style=\"color: #999999;\">20<\/li>\n<li style=\"color: #999999;\">21<\/li>\n<li style=\"color: #999999;\">22<\/li>\n<li style=\"color: #999999;\">23<\/li>\n<li style=\"color: #999999;\">24<\/li>\n<li style=\"color: #999999;\">25<\/li>\n<li style=\"color: #999999;\">26<\/li>\n<\/ul>\n<p style=\"font-style: inherit; color: #4f4f4f;\">\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u6784\u5efa\u4e86\u4e00\u4e2a\u4e09\u89d2\u5f62\u62d3\u6251\uff0c\u6bcf\u4e2a\u70b9\u6709\u5c5e\u6027desc\uff0c\u7528\u4e8e\u5b58\u50a8\u8fd9\u4e2a\u70b9\u7684\u63cf\u8ff0\u4fe1\u606f\uff0c\u540c\u65f6\u6bcf\u6761\u8fb9\u6709\u4e2a\u5c5e\u6027name\u3002\u6211\u4eec\u60f3\u5728\u56fe\u4e2d\u5c06desc\u5c5e\u6027\u548cname\u5c5e\u6027\u5c55\u793a\u51fa\u6765\uff0c\u7531\u4e8e\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709desc\u5c5e\u6027\uff0c\u6240\u4ee5\u6211\u4eec\u76f4\u63a5\u8c03\u7528<span style=\"color: red;\">nx.get_node_attributes(G, \u2018desc\u2019)<\/span>\u6765\u83b7\u5f97\u7684node_labels\u3002edge_labels\u7684\u83b7\u53d6\u540c\u7406\u3002\u6700\u540e\u7684\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.freesion.com\/images\/368\/4a9750255cff63845023603a2631a548.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<hr \/>\n<h2 style=\"font-weight: bold; font-style: inherit; color: #4f4f4f;\">\u4f8b\u5b502<\/h2>\n<p style=\"font-style: inherit; color: #4f4f4f;\">\u5728\u4f8b\u5b501\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7get_node_attributes\u548cget_edge_attributes\u5f88\u65b9\u4fbf\u7684\u5f97\u5230\u4e86node_labels\u548cedge_labels\uff0c\u4f46\u662f\u8fd9\u79cd\u65b9\u6cd5\u6709\u4e00\u4e2a\u7f3a\u9677\uff0c\u90a3\u5c31\u662f\u53ea\u80fd\u83b7\u53d6\u5e76\u5c55\u793a\u4e00\u4e2a\u5c5e\u6027\u3002\u800c\u8282\u70b9\u6216\u8fb9\u6709\u591a\u4e2a\u5c5e\u6027\u662f\u5f88\u6b63\u5e38\u7684\u60c5\u51b5\uff0c\u6240\u4ee5\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5c06\u4f1a\u5c55\u793a\u5982\u4f55\u5c06\u591a\u4e2a\u5c5e\u6027\u540c\u65f6\u5728\u56fe\u4e2d\u663e\u793a\u3002<\/p>\n<p style=\"font-style: inherit; color: #4f4f4f;\">\u5728\u4f8b\u5b501\u7684\u57fa\u7840\u4e0a\uff0c\u6211\u4eec\u4e3a\u6bcf\u4e2a\u8282\u70b9\u589e\u52a0\u4e00\u4e2a\u65b0\u7684\u5c5e\u6027attr1\uff0c\u5e76\u5728\u56fe\u4e2d\u8fdb\u884c\u5c55\u793a\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"prettyprint\" style=\"font-weight: inherit; font-style: inherit; color: #000000;\"><code class=\"has-numbering\" style=\"font-weight: inherit; font-style: inherit; color: #abb2bf;\">import networkx as nx\r\nimport matplotlib.pyplot as plt\r\n\r\ndef main():\r\n    G = nx.Graph()\r\n    \r\n    #topology construction logic\r\n    G.add_node('s1', desc='I am switch 1', attr1='new attr1')\r\n    G.add_node('s2', desc='I am switch 2', attr1='new attr1')\r\n    G.add_node('s3', desc='I am switch 3', attr1='new attr1')\r\n    G.add_edge('s1','s2', name='edge 0')\r\n    G.add_edge('s1','s3', name='edge 1')\r\n    G.add_edge('s2','s3', name='edge 2')\r\n    \r\n    #draw graph with labels\r\n    pos = nx.spring_layout(G)\r\n    nx.draw(G, pos)\r\n    \r\n    #Generate node_labels manually\r\n    node_labels = {}\r\n    for node in G.nodes:\r\n        node_labels[node] = G.nodes[node] #G.nodes[node] will return all attributes of node\r\n    \r\n    nx.draw_networkx_labels(G, pos, labels=node_labels)\r\n    edge_labels = nx.get_edge_attributes(G, 'name')\r\n    nx.draw_networkx_edge_labels(G, pos, labels=edge_labels)\r\n    plt.show()\r\n\r\n\r\nif __name__ == '__main__':\r\n    main()\r\n<\/code><\/pre>\n<ul class=\"pre-numbering\">\n<li style=\"color: #999999;\">1<\/li>\n<li style=\"color: #999999;\">2<\/li>\n<li style=\"color: #999999;\">3<\/li>\n<li style=\"color: #999999;\">4<\/li>\n<li style=\"color: #999999;\">5<\/li>\n<li style=\"color: #999999;\">6<\/li>\n<li style=\"color: #999999;\">7<\/li>\n<li style=\"color: #999999;\">8<\/li>\n<li style=\"color: #999999;\">9<\/li>\n<li style=\"color: #999999;\">10<\/li>\n<li style=\"color: #999999;\">11<\/li>\n<li style=\"color: #999999;\">12<\/li>\n<li style=\"color: #999999;\">13<\/li>\n<li style=\"color: #999999;\">14<\/li>\n<li style=\"color: #999999;\">15<\/li>\n<li style=\"color: #999999;\">16<\/li>\n<li style=\"color: #999999;\">17<\/li>\n<li style=\"color: #999999;\">18<\/li>\n<li style=\"color: #999999;\">19<\/li>\n<li style=\"color: #999999;\">20<\/li>\n<li style=\"color: #999999;\">21<\/li>\n<li style=\"color: #999999;\">22<\/li>\n<li style=\"color: #999999;\">23<\/li>\n<li style=\"color: #999999;\">24<\/li>\n<li style=\"color: #999999;\">25<\/li>\n<li style=\"color: #999999;\">26<\/li>\n<li style=\"color: #999999;\">27<\/li>\n<li style=\"color: #999999;\">28<\/li>\n<li style=\"color: #999999;\">29<\/li>\n<li style=\"color: #999999;\">30<\/li>\n<li style=\"color: #999999;\">31<\/li>\n<\/ul>\n<p style=\"font-style: inherit; color: #4f4f4f;\">\u8fd9\u65ad\u4ee3\u7801\u7684\u5173\u952e\u5728\u4e8e\u6211\u4eec\u4e0d\u518d\u901a\u8fc7nx.get_node_attributes\u6765\u83b7\u53d6node_labels\uff0c\u800c\u662f<span style=\"color: red;\">\u624b\u5de5\u6784\u5efa\u4e86node_labels<\/span><\/p>\n<p style=\"font-style: inherit; color: #4f4f4f;\">\u6700\u540e\u7684\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.freesion.com\/images\/213\/04cce93e92119ebac72ece9816217e45.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<blockquote style=\"font-weight: inherit; font-style: italic; color: rgba(0, 0, 0, 0.5);\">\n<p style=\"font-style: inherit; color: #999999;\">\u6ce8\uff1a\u7531\u4e8e\u5e03\u5c40\u7684\u539f\u56e0\uff0c\u8282\u70b9\u7684\u5185\u5bb9\u6ca1\u6709\u663e\u793a\u5b8c\u6574\uff0c\u5728\u5b9e\u9645\u4f7f\u7528\u8fc7\u7a0b\u4e2d\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u7684\u62d3\u6251\u5c1d\u8bd5\u4e0d\u540c\u7684layout\u65b9\u5f0f\u6765\u8fbe\u5230\u7406\u60f3\u7684\u5c55\u793a\u6548\u679c\uff0c\u8fd9\u91cc\u6211\u6545\u610f\u6ca1\u6709\u8c03\u6574\u5c31\u662f\u4e3a\u4e86\u8bf4\u660e\u8fd9\u4e00\u70b9\u3002<\/p>\n<\/blockquote>\n<hr \/>\n<h2 style=\"font-weight: bold; font-style: inherit; color: #4f4f4f;\">\u4f8b\u5b503<\/h2>\n<p style=\"font-style: inherit; color: #4f4f4f;\">\u5f53\u7136\uff0c\u6211\u4eec\u4e0d\u4ec5\u53ef\u4ee5\u663e\u793a\u5c5e\u6027\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u663e\u793a\u4efb\u4f55\u6211\u4eec\u60f3\u8981\u663e\u793a\u7684\u5185\u5bb9\uff0c\u53ea\u8981<span style=\"color: red;\">\u6b63\u786e\u7684\u751f\u6210\u4e86node_labels\u4e0eedge_labels\u5373\u53ef<\/span>\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f9d\u7136\u4f7f\u7528\u4e09\u89d2\u5f62\u62d3\u6251\uff0c\u53ea\u4e0d\u8fc7\u6211\u4eec\u73b0\u5728\u5728\u8282\u70b9\u4e0a\u663e\u793a\u4e9b\u4e0d\u4e00\u6837\u7684\u5185\u5bb9\uff1a<\/p>\n<pre class=\"prettyprint\" style=\"font-weight: inherit; font-style: inherit; color: #000000;\"><code class=\"has-numbering\" style=\"font-weight: inherit; font-style: inherit; color: #abb2bf;\">import networkx as nx\r\nimport matplotlib.pyplot as plt\r\n\r\ndef main():\r\n    G = nx.Graph()\r\n    \r\n    #topology construction logic\r\n    G.add_node('s1', desc='I am switch 1', attr1='new attr1')\r\n    G.add_node('s2', desc='I am switch 2', attr1='new attr1')\r\n    G.add_node('s3', desc='I am switch 3', attr1='new attr1')\r\n    G.add_edge('s1','s2', name='edge 0')\r\n    G.add_edge('s1','s3', name='edge 1')\r\n    G.add_edge('s2','s3', name='edge 2')\r\n    \r\n    #draw graph with labels\r\n    pos = nx.spring_layout(G)\r\n    nx.draw(G, pos)\r\n    \r\n    #Generate node_labels manually\r\n    node_labels = {}\r\n    for node in G.nodes:\r\n        node_labels[node] = 'Hello\\n I am node: ' + str(node)\r\n    \r\n    nx.draw_networkx_labels(G, pos, labels=node_labels)\r\n    edge_labels = nx.get_edge_attributes(G, 'name')\r\n    nx.draw_networkx_edge_labels(G, pos, labels=edge_labels)\r\n    plt.show()\r\n\r\n\r\nif __name__ == '__main__':\r\n    main()\r\n<\/code><\/pre>\n<ul class=\"pre-numbering\">\n<li style=\"color: #999999;\">1<\/li>\n<li style=\"color: #999999;\">2<\/li>\n<li style=\"color: #999999;\">3<\/li>\n<li style=\"color: #999999;\">4<\/li>\n<li style=\"color: #999999;\">5<\/li>\n<li style=\"color: #999999;\">6<\/li>\n<li style=\"color: #999999;\">7<\/li>\n<li style=\"color: #999999;\">8<\/li>\n<li style=\"color: #999999;\">9<\/li>\n<li style=\"color: #999999;\">10<\/li>\n<li style=\"color: #999999;\">11<\/li>\n<li style=\"color: #999999;\">12<\/li>\n<li style=\"color: #999999;\">13<\/li>\n<li style=\"color: #999999;\">14<\/li>\n<li style=\"color: #999999;\">15<\/li>\n<li style=\"color: #999999;\">16<\/li>\n<li style=\"color: #999999;\">17<\/li>\n<li style=\"color: #999999;\">18<\/li>\n<li style=\"color: #999999;\">19<\/li>\n<li style=\"color: #999999;\">20<\/li>\n<li style=\"color: #999999;\">21<\/li>\n<li style=\"color: #999999;\">22<\/li>\n<li style=\"color: #999999;\">23<\/li>\n<li style=\"color: #999999;\">24<\/li>\n<li style=\"color: #999999;\">25<\/li>\n<li style=\"color: #999999;\">26<\/li>\n<li style=\"color: #999999;\">27<\/li>\n<li style=\"color: #999999;\">28<\/li>\n<li style=\"color: #999999;\">29<\/li>\n<li style=\"color: #999999;\">30<\/li>\n<li style=\"color: #999999;\">31<\/li>\n<\/ul>\n<p style=\"font-style: inherit; color: #4f4f4f;\">\u4e0e\u4f8b\u5b502\u7c7b\u4f3c\uff0c\u6211\u4eec\u518d\u6b21\u624b\u52a8\u6784\u5efa\u4e86node_labels\u7684\u5185\u5bb9\uff0c\u73b0\u5728\u7684\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\u6240\u793a\uff1a<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.freesion.com\/images\/679\/fd00b7803ce63b8a8b9c5aca1da4fd5f.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><br \/>\n\u8fd9\u6837\uff0c\u6211\u4eec\u5c31\u5728\u8282\u70b9\u4e0a\u663e\u793a\u4e86Hello\u4fe1\u606f\uff01<\/p>\n<hr \/>\n<h2 style=\"font-weight: bold; font-style: inherit; color: #4f4f4f;\">\u603b\u7ed3<\/h2>\n<p style=\"font-style: inherit; color: #4f4f4f;\">\u901a\u8fc7\u4ee5\u4e0a\u7684\u8bb2\u89e3\u4ee5\u53ca\u4f8b\u5b50\uff0c\u6211\u76f8\u4fe1\u4f60\u5e94\u8be5\u5df2\u7ecf\u57fa\u672c\u638c\u63e1\u4e86\u5728networkx\u56fe\u4e2d\u5c55\u793a\u8282\u70b9\u548c\u8fb9\u7684\u5c5e\u6027\u7684\u65b9\u6cd5\uff0c\u5176\u5b9e<span style=\"color: red;\">\u6838\u5fc3\u5c31\u662f\u5229\u7528\u4e24\u4e2a\u51fd\u6570\uff1a<\/span><\/p>\n<pre class=\"prettyprint\" style=\"font-weight: inherit; font-style: inherit; color: #000000;\"><code class=\"has-numbering\" style=\"font-weight: inherit; font-style: inherit; color: #abb2bf;\">draw_networkx_labels(G, pos, labels=a dictionary used to describe what you want to show in node)\r\ndraw_networkx_edge_labels(G, pos, labels=a dictionary used to describe what you want to show in edge)\r\n<\/code><\/pre>\n<ul class=\"pre-numbering\">\n<li style=\"color: #999999;\">1<\/li>\n<li style=\"color: #999999;\">2<\/li>\n<\/ul>\n<p style=\"font-style: inherit; color: #4f4f4f;\">\u5e76<span style=\"color: red;\">\u6839\u636e\u9700\u6c42\u4f20\u5165\u76f8\u5e94\u7684node_labels\u4e0eedge_labels\u5373\u53ef\u3002<\/span><\/p>\n<p style=\"font-style: inherit; color: #4f4f4f;\">\u5f53\u9700\u8981\u5c55\u793a\u7684\u5c5e\u6027\u53ea\u6709\u4e00\u4e2a\u65f6\uff0cnode_labels\u4e0eedge_labels\u7684\u6784\u5efa\u53ef\u4ee5\u501f\u52a9\u4ee5\u4e0b\u4e24\u4e2a\u51fd\u6570\uff1a<\/p>\n<pre class=\"prettyprint\" style=\"font-weight: inherit; font-style: inherit; color: #000000;\"><code class=\"has-numbering\" style=\"font-weight: inherit; font-style: inherit; color: #abb2bf;\">get_node_attributes(G, node_attributes_name)\r\nget_edge_attributes(G, edge_attributes_name)\r\n<\/code><\/pre>\n<ul class=\"pre-numbering\">\n<li style=\"color: #999999;\">1<\/li>\n<li style=\"color: #999999;\">2<\/li>\n<\/ul>\n<p style=\"font-style: inherit; color: #4f4f4f;\">\u5982\u679c\u9700\u8981\u5c55\u793a\u4e24\u4e2a\u53ca\u4ee5\u4e0a\u7684\u5c5e\u6027\uff0c\u6216\u8005\u662f\u60f3\u5c55\u793a\u4e00\u4e9b\u81ea\u5b9a\u4e49\u7684\u5185\u5bb9\uff0c\u90a3\u5c31\u9700\u8981\u624b\u52a8\u6784\u5efanode_labels\u4e0eedge_labels\u5566\uff01\u6784\u5efa\u65b9\u6cd5\u5728\u4f8b\u5b502\u4e0e\u4f8b\u5b503\u4e2d\u5747\u6709\u5c55\u793a\u3002<\/p>\n<p>frome: https:\/\/www.freesion.com\/article\/2236407496\/<\/p>\n<\/div>\n<\/div>\n<div id=\"article_bottom_ads\" style=\"color: rgba(0, 0, 0, 0.75);\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>python\u7684NetworkX\u5e93\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u6784\u5efa\u7f51\u7edc\u62d3\u6251\u5e76\u5b9e\u73b0\u62d3\u6251\u7684\u53ef\u89c6\u5316\uff0c\u8fd9\u5bf9\u4e8e\u7f51\u7edc\u7814\u7a76\uff0c\u65e5\u5e38\u5c55\u793a\u7b49\u90fd\u662f\u5341\u5206\u7684\u65b9\u4fbf\u3002\u4e0d\u8fc7\uff0c\u6211\u53d1\u73b0\u5e76\u6ca1\u6709\u6587\u7ae0\u6bd4\u8f83\u7cfb\u7edf\u7684\u4ecb\u7ecd\u5982\u4f55\u5728\u53ef\u89c6\u5316\u7684\u56fe\u4e2d\u5c55\u793a\u8282\u70b9\u548c\u8fb9\u7684\u5c5e\u6027\uff0c\u4ece\u800c\u8ba9\u56fe\u66f4\u52a0\u7684\u5177\u4f53\uff0c\u76f4\u89c2\u3002\u56e0\u6b64\u5c31\u60f3\u5199\u4e00\u7bc7\u6587\u7ae0\u6765\u6559 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-444","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=444"}],"version-history":[{"count":1,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/444\/revisions"}],"predecessor-version":[{"id":445,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/444\/revisions\/445"}],"wp:attachment":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=444"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}