3

I want to visualize my data. my data is like: my data file is :https://gist.github.com/anonymous/5568836

4556    5092    0.7000 
4556    4785    0.7500 
4556    5397    0.7000 
4556    5139    0.7500 
4556    5937    0.8333 
4556    6220    0.7000 
4556    5139    0.7500 
4556    6220    0.7063 
4559    4563    0.7500 
4559    4770    0.7500 
4559    4837    0.7500 
4559    5640    0.7500 
4559    4563    0.7500 
4559    4770    0.7500 
4559    4837    0.7500 
4559    5640    0.7500 
4561    4607    1.0000 
4561    4600    0.7500 
4561    4562    0.7500 
4561    5090    0.7500 
4561    5197    1.0000 
4561    5182    0.7500 
4561    5937    0.7500 
4561    6143    0.7500 
4561    5632    1.0000 

the first is the source node,and the second is the target node,and the third is there distance. I have use networkx to visualize it,my code is:

import matplotlib.pyplot as plt
import networkx as nx
G=nx.Graph()
#G=nx.star_graph(800)
filedata1 = open("1.txt",'r')
for line in filedata1:
    datas = line.split()
    G.add_node(int(datas[0]))
    G.add_node(int(datas[1]))
    G.add_edge(int(datas[0]),int(datas[1]),weight=float(datas[2]))
pos=nx.spring_layout(G)
nx.draw_networkx_nodes(G,pos,node_size=20,node_color='r')
plt.axis('off')
plt.savefig("data.png")
plt.show()

and the output is : enter image description here

and the same data,I use cytoscape,the out is: enter image description here

the cytoscape seems to auto cluster the data,so I can see some cluster,in networkx,it totally mess.

I want to the output like in cytospace,but cytospace output have links and can't set the distance between the nodes.

networkx can set the edge distance between nodes and can only draw the nodes(this is what I want),but the layout is totally mess,I want to show some cluster :-)

It seems the cytospace use the force layout,and I use force layout in networkx,but the output is totally different.

anyone can give me some help? thx

kuafu
  • 1,466
  • 5
  • 17
  • 28

1 Answers1

2

If you can install pydot or pygraphviz you might have better luck with the graphviz layout engine.

E.g.

import matplotlib.pyplot as plt
import networkx as nx
import urllib
data = urllib.urlopen('https://gist.github.com/anonymous/5568836/raw/abc598d68d8fef980c9701b4bc85f5d10a9f71fa/gistfile1.txt')
G = nx.read_weighted_edgelist(data)
pos=nx.graphviz_layout(G)
nx.draw(G,pos,node_size=20,node_color='r',with_labels=False)
plt.savefig("data.png")
plt.show()

enter image description here

Aric
  • 24,511
  • 5
  • 78
  • 77