Closed fishbacp closed 1 year ago
That is the correct format for node_labels
and on my machine this works as intended:
import matplotlib.pyplot as plt
import networkx as nx
from netgraph import Graph
# create a modular graph
partition_sizes = [3, 4, 3]
g = nx.random_partition_graph(partition_sizes, 1.0, 0.5)
# create a dictionary that maps nodes to the community they belong to
node_to_community = dict()
node = 0
for community_id, size in enumerate(partition_sizes):
for _ in range(size):
node_to_community[node] = community_id
node += 1
community_to_color = {
0 : 'tab:blue',
1 : 'tab:orange',
2 : 'tab:green',
3 : 'tab:red',
}
node_color = {node: community_to_color[community_id] for node, community_id in node_to_community.items()}
node_labels = dict(zip(range(10), 'abcdefghij'))
Graph(g,
node_color=node_color, node_labels=node_labels, node_edge_width=0, edge_alpha=0.1,
node_layout='community', node_layout_kwargs=dict(node_to_community=node_to_community),
edge_layout='bundled', edge_layout_kwargs=dict(k=2000),
)
plt.show()
Since you closed the issue yourself, did you work out what was going wrong?
I've run the sample plot_10_community_layout.py using
partition_sizes = [3,4,3]
. Suppose my node labels are the letters A-J. I tried settingnode_labels={0:'A',1:'B',2:'C',3:'D',4:'E',5:'F',6:'G',7:'H',8:'I',9:'J'}
and passingnode_labels=node_labels
as an argument toGraph
but received the error message below. Is there a different way I should enter my labels?