Mercurial > repos > shellac > sam_consensus_v3
comparison env/share/doc/networkx-2.5/examples/drawing/plot_directed.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 Directed Graph | |
4 ============== | |
5 | |
6 Draw a graph with directed edges using a colormap and different node sizes. | |
7 | |
8 Edges have different colors and alphas (opacity). Drawn using matplotlib. | |
9 """ | |
10 | |
11 import matplotlib as mpl | |
12 import matplotlib.pyplot as plt | |
13 import networkx as nx | |
14 | |
15 G = nx.generators.directed.random_k_out_graph(10, 3, 0.5) | |
16 pos = nx.layout.spring_layout(G) | |
17 | |
18 node_sizes = [3 + 10 * i for i in range(len(G))] | |
19 M = G.number_of_edges() | |
20 edge_colors = range(2, M + 2) | |
21 edge_alphas = [(5 + i) / (M + 4) for i in range(M)] | |
22 | |
23 nodes = nx.draw_networkx_nodes(G, pos, node_size=node_sizes, node_color="blue") | |
24 edges = nx.draw_networkx_edges( | |
25 G, | |
26 pos, | |
27 node_size=node_sizes, | |
28 arrowstyle="->", | |
29 arrowsize=10, | |
30 edge_color=edge_colors, | |
31 edge_cmap=plt.cm.Blues, | |
32 width=2, | |
33 ) | |
34 # set alpha value for each edge | |
35 for i in range(M): | |
36 edges[i].set_alpha(edge_alphas[i]) | |
37 | |
38 pc = mpl.collections.PatchCollection(edges, cmap=plt.cm.Blues) | |
39 pc.set_array(edge_colors) | |
40 plt.colorbar(pc) | |
41 | |
42 ax = plt.gca() | |
43 ax.set_axis_off() | |
44 plt.show() |