17

I am working on a pagerank algorithm using Networkx module in Python. I have a dictionary of lists, where key of the dictionary is the Title of the page and its value is all the Titles referenced through that page.

So in order to create a visualization, I first did this:

G = nx.DiGraph()
G = nx.from_dict_of_lists(ref_dict)

where ref_dict is the dictionary mentioned above.

After creating the graph, I am using Networkx's write_edgelist function to store the Graph in the csv format.

nx.write_edgelist(subG,'PageRanks2.csv')

Herein lies my problem. The csv file is storing edges as:

node1 node2 {} node1 node3 {}

When I am using this file directly in Gephi, it treats the {} as a node and shows visualization accordingly. So what should be the best format to store the networkx graph to visualize it?

PySerial Killer
  • 428
  • 1
  • 9
  • 26
Suyash
  • 195
  • 1
  • 1
  • 9

2 Answers2

23

Use write_gexf function like: nx.write_gexf(G, "test.gexf"), and open the file using Gephi, then you'll see it.

Reference https://networkx.github.io/documentation/networkx-1.10/reference/generated/networkx.readwrite.gexf.write_gexf.html#write-gexf

Edward
  • 554
  • 8
  • 15
semenbari
  • 725
  • 1
  • 8
  • 22
3

You can specify data argument to tell networkx not to add {}:

nx.write_edgelist(subG,'PageRanks2.csv', data=False)

There are other formats which both networkx and gephy support (e.g. GraphML), and you can accomplish much more complex data visualization tasks if your data has attributes associated with it.

Alz
  • 755
  • 6
  • 11