Plot bars charts with the degree and weights. Degree is the number of 'out-edges' and the weights are the outward data volume for each rank.
(G: nx.MultiGraph)
| 92 | |
| 93 | # + |
| 94 | def plot_bar(G: nx.MultiGraph): |
| 95 | """Plot bars charts with the degree and weights. |
| 96 | |
| 97 | Degree is the number of 'out-edges' and the weights are the outward |
| 98 | data volume for each rank. |
| 99 | """ |
| 100 | ranks = range(G.order()) |
| 101 | num_edges = [len(nbrs) for _, nbrs in G.adj.items()] |
| 102 | weights = [sum(data["weight"] for nbr, data in nbrs.items()) for _, nbrs in G.adj.items()] |
| 103 | |
| 104 | _fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5)) |
| 105 | |
| 106 | ax1.bar(ranks, num_edges) |
| 107 | ax1.set_xlabel("rank") |
| 108 | ax1.set_ylabel("out degree") |
| 109 | ax1.xaxis.set_major_locator(MaxNLocator(integer=True)) |
| 110 | ax1.yaxis.set_major_locator(MaxNLocator(integer=True)) |
| 111 | |
| 112 | ax2.bar(ranks, weights) |
| 113 | ax2.set_xlabel("rank") |
| 114 | ax2.set_ylabel("sum of edge weights") |
| 115 | ax2.xaxis.set_major_locator(MaxNLocator(integer=True)) |
| 116 | ax2.yaxis.set_major_locator(MaxNLocator(integer=True)) |
| 117 | |
| 118 | |
| 119 | # - |