Skip to content

Visualizing the output of a hierarchical clustering #211

@dror-kris

Description

@dror-kris

I'm trying to utilize the Paris algorithm for hierarchical community detection.

When I attempt to visualize the network and communities, I encounter the following error:

KeyError                                  Traceback (most recent call last)
~\anaconda3\envs\cdlib\lib\site-packages\networkx\drawing\nx_pylab.py in draw_networkx_nodes(G, pos, nodelist, node_size, node_color, node_shape, alpha, cmap, vmin, vmax, ax, linewidths, edgecolors, label, margins)
    455     try:
--> 456         xy = np.asarray([pos[v] for v in nodelist])
    457     except KeyError as err:

~\anaconda3\envs\cdlib\lib\site-packages\networkx\drawing\nx_pylab.py in <listcomp>(.0)
    455     try:
--> 456         xy = np.asarray([pos[v] for v in nodelist])
    457     except KeyError as err:

KeyError: 656

The above exception was the direct cause of the following exception:

NetworkXError                             Traceback (most recent call last)
<ipython-input-62-3db2159df5b2> in <module>
----> 1 viz.plot_network_clusters(G, coms)

c:\users\work\src\cdlib\cdlib\viz\networks.py in plot_network_clusters(graph, partition, position, figsize, node_size, plot_overlaps, plot_labels, cmap, top_k, min_size)
    113         )
    114     )
--> 115     fig = nx.draw_networkx_nodes(
    116         graph, position, node_size=node_size, node_color="w", nodelist=filtered_nodelist
    117     )

~\anaconda3\envs\cdlib\lib\site-packages\networkx\drawing\nx_pylab.py in draw_networkx_nodes(G, pos, nodelist, node_size, node_color, node_shape, alpha, cmap, vmin, vmax, ax, linewidths, edgecolors, label, margins)
    456         xy = np.asarray([pos[v] for v in nodelist])
    457     except KeyError as err:
--> 458         raise nx.NetworkXError(f"Node {err} has no position.") from err
    459 
    460     if isinstance(alpha, Iterable):

NetworkXError: Node 656 has no position.

Should I be using an alternative visualization method?
On the github page for the Paris package (https://github.com/tbonald/paris), I see the following visualization:

from utils import plot_dendrogram

plot_dendrogram(D)

Additionally, when attempting to map the partition using coms.to_node_community_map() I lose the hierarchies between communities - is there a better way to work with the partition output?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions