Search code examples
pythonnetworkxkeyword-argument

TypeError: draw_networkx_labels() got an unexpected keyword argument "node_color"


I am using the networkx package to calculate the community network for frequency counts using cosine similarity below is the part of the code where I am trying to draw the network graph and I get this error.

S=nx.Graph()   #   draws the community detection graph
S.add_nodes_from(names)
S.add_weighted_edges_from(sim_edges)

pos1 = nx.spring_layout(S) 

plt.figure(figsize=(10,10),dpi=200)
part = community_louvain.best_partition(S) 
values = [part.get(node) for node in S.nodes()] 
nx.draw_networkx_nodes(S,pos=pos1,node_color = values, node_size=8400, cmap =cmap1)
nx.draw_networkx_labels(S,pos=pos1,node_color = values, node_size=8400, font_size=10)
nx.draw_networkx_edges(S,pos=pos1, edgelist=edge_weights.keys(),width=list(edge_weights.values())) 
plt.axis('off')

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-32-ae3fd091a221> in <module>
     47 values = [part.get(node) for node in S.nodes()] #get all names in network go to the partition get entry from the partitionget entry with node name - values is a list of entries that were the value in partition got by looking up each node name in network
     48 nx.draw_networkx_nodes(S,pos=pos1,node_color = values, node_size=8400, cmap =cmap1) #colour nodes by which community they in
---> 49 nx.draw_networkx_labels(S,pos=pos1,node_color = values, node_size=8400, font_size=10)
     50 nx.draw_networkx_edges(S,pos=pos1, edgelist=edge_weights.keys(),width=list(edge_weights.values())) #keys are the edges and weights are values -edge weight dcitionary get edges and values
     51 plt.axis('off')

TypeError: draw_networkx_labels() got an unexpected keyword argument 'node_color'

Solution

  • From the networkX documentation on draw_networkx_labels,
    The available parameters do not include node_color, instead if you want you may change the font color as well as it's transparency:

    font_color (string) – Font color string (default=’k’ black)
    alpha (float or None) – The text transparency (default=None)