Mercurial > repos > shellac > sam_consensus_v3
comparison env/share/doc/networkx-2.5/examples/drawing/plot_weighted_graph.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 """ | |
2 ============== | |
3 Weighted Graph | |
4 ============== | |
5 | |
6 An example using Graph as a weighted network. | |
7 """ | |
8 import matplotlib.pyplot as plt | |
9 import networkx as nx | |
10 | |
11 G = nx.Graph() | |
12 | |
13 G.add_edge("a", "b", weight=0.6) | |
14 G.add_edge("a", "c", weight=0.2) | |
15 G.add_edge("c", "d", weight=0.1) | |
16 G.add_edge("c", "e", weight=0.7) | |
17 G.add_edge("c", "f", weight=0.9) | |
18 G.add_edge("a", "d", weight=0.3) | |
19 | |
20 elarge = [(u, v) for (u, v, d) in G.edges(data=True) if d["weight"] > 0.5] | |
21 esmall = [(u, v) for (u, v, d) in G.edges(data=True) if d["weight"] <= 0.5] | |
22 | |
23 pos = nx.spring_layout(G) # positions for all nodes | |
24 | |
25 # nodes | |
26 nx.draw_networkx_nodes(G, pos, node_size=700) | |
27 | |
28 # edges | |
29 nx.draw_networkx_edges(G, pos, edgelist=elarge, width=6) | |
30 nx.draw_networkx_edges( | |
31 G, pos, edgelist=esmall, width=6, alpha=0.5, edge_color="b", style="dashed" | |
32 ) | |
33 | |
34 # labels | |
35 nx.draw_networkx_labels(G, pos, font_size=20, font_family="sans-serif") | |
36 | |
37 plt.axis("off") | |
38 plt.show() |