Search code examples
pythongraphnetworkxlabel

How to add labels to nodes in a CIRCULAR GRAPH with networkx in python


I'm drawing a circular graph using the method:

nx.draw_circular(G, node_color='b', edge_color='#909090', node_size=500)

Basically what I want to do is to add labels to the nodes but I don't find the way to add them in this type of graphs. I tried using:

nx.draw_networkx_labels(G,labels=labels,pos=nx.spring_layout(G),font_size=16)

but there is a problem with the position layout, it is not next/in each node.

enter image description here


Solution

  • Solved!

    G=nx.Graph()
    G.add_nodes_from(range(20))
    e = [(0,1),(0,2)]
    G.add_edges_from(e)
    
    # some labels
    labels={}
    
    nx.draw_circular(G, node_color='y', edge_color='#909090', node_size=500,labels=labels)
    
    plt.axis('equal')
    

    enter image description here