Search code examples
pythonpandasnetworkx

networkX.draw() not producing edges


I'm not sure why my network graph doesn't include edges.

I'm creating a network from a pandas dataframe that looks like the following:

enter image description here

I created the network as follows:

G = nx.from_pandas_edgelist(network_df,
                      edge_attr='weight',
                      source='Source',
                      target='Target',
                      create_using=nx.Graph())

but nx.draw(G) produces a graph without edges.

enter image description here

I tried using nx.DigGraph() but the result is the same.

Any help is greatly appreciated.


Solution

  • That central "blob" in your plot is a lot of nodes connected together which probably do have edges, but they are obscured by the dense mass of nodes. On the periphery there are a few nodes joined together by edges, but due to the plotting algorithm they pairs (or somewhat larger cluster) are again so close together that the nodes are obscured. The isolated nodes are isolated.

    It's probably best to try another layout. The default is spring_layout. Here's another that will probably show it better:

    pos = nx.circular_layout(G)
    nx.draw(G, pos)
    

    As a general rule, networkx was not designed for the purpose of graph visualization. So you may need to look at other tools like graphviz.