diff options
author | Jarrod Millman <jarrod.millman@gmail.com> | 2020-12-03 07:07:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-03 07:07:24 -0800 |
commit | 7af4df0e9251adcec081caec7ed6d8384af5be2c (patch) | |
tree | 45afe9f184108801b223e98456c9363b55e37950 /examples | |
parent | 0ead17fb18334040b84dd614d1f12d6d3fa9e130 (diff) | |
download | networkx-7af4df0e9251adcec081caec7ed6d8384af5be2c.tar.gz |
Add plot for rcm example (#4411)
Diffstat (limited to 'examples')
-rw-r--r-- | examples/algorithms/plot_rcm.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/examples/algorithms/plot_rcm.py b/examples/algorithms/plot_rcm.py index 8ea926e7..61b49bb7 100644 --- a/examples/algorithms/plot_rcm.py +++ b/examples/algorithms/plot_rcm.py @@ -1,18 +1,21 @@ """ -=== -Rcm -=== +====================== +Reverse Cuthill--McKee +====================== Cuthill-McKee ordering of matrices -The reverse Cuthill-McKee algorithm gives a sparse matrix ordering that +The reverse Cuthill--McKee algorithm gives a sparse matrix ordering that reduces the matrix bandwidth. """ import networkx as nx from networkx.utils import reverse_cuthill_mckee_ordering +import matplotlib.pyplot as plt +import seaborn as sns import numpy as np + # build low-bandwidth numpy matrix G = nx.grid_2d_graph(3, 3) rcm = list(reverse_cuthill_mckee_ordering(G)) @@ -33,3 +36,6 @@ x, y = np.nonzero(B) # print(f"upper bandwidth: {(x - y).max()}") print(f"bandwidth: {(y - x).max() + (x - y).max() + 1}") print(B) + +sns.heatmap(B.todense(), cbar=False, square=True, linewidths=0.5, annot=True) +plt.show() |