Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store a networkx graph for visualizing in Gephi?

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?

like image 270
Suyash Avatar asked Sep 01 '17 22:09

Suyash


People also ask

How is a graph stored in NetworkX?

NetworkX uses dicts to store the nodes and neighbors in a graph. So the reporting of nodes and edges for the base graph classes will not necessarily be consistent across versions and platforms.

How do I export a Gephi graph?

To save as a graph file, go to File -> Export -> Graph File and select your preferred format. To save as an image or PDF file, go to File -> Export -> SVG/PDF/PNG File. If installed, several optional Gephi plugins will also allow you to export to an interactive web project that can be easily embedded into your website.

What is used to visualize NetworkX graphs?

NetworkX has its own drawing module which provides multiple options for plotting. Below we can find the visualization for some of the draw modules in the package. Using any of them is fairly easy, as all you need to do is call the module and pass the G graph variable and the package does the rest.


1 Answers

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

like image 197
semenbari Avatar answered Sep 28 '22 06:09

semenbari