擅长:python、mysql、java
<p>以下是不同颜色边的示例:</p>
<pre><code>import matplotlib.pyplot as plt
import networkx as nx
G = nx.cubical_graph()
pos = nx.spring_layout(G)
nx.draw_networkx_nodes(G, pos, nodelist=[0, 1, 2, 3], node_color='y')
nx.draw_networkx_nodes(G, pos, nodelist=[4, 5, 6, 7], node_color='g')
nx.draw_networkx_edges(G, pos, edgelist=[(0, 1), (1, 2), (2, 3), (3, 0)], edge_color='y')
nx.draw_networkx_edges(G, pos, edgelist=[(4, 6), (6, 5), (5, 7), (7, 4)], edge_color='g')
nx.draw_networkx_labels(G, pos)
plt.show()
</code></pre>
<p>输出:</p>
<p><a href="https://i.stack.imgur.com/GGtQK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GGtQK.png" alt="Image"/></a></p>
<p>有关更多信息,请参阅<a href="https://networkx.github.io/documentation/stable/auto_examples/drawing/plot_labels_and_colors.html" rel="nofollow noreferrer">documentation</a></p>