문제

I am looking to convert a Pajek dataset into a networkx Graph(). The dataset comes from Costa Rican Family Ties. I am using the very handy networkx.read_pajek(pathname) function, but am running into some trouble. I do the following commands on my terminal window (iPython) after changing to the right directory, importing networkx as nx and matplotlib.pyplot as plt:

>> G = nx.read_pajek('SanJuanSur.paj')
>> nx.draw(G)
>> fig = plt.figure(figsize = (15, 10))
>> nx.draw(G)
>> plt.show()

Output of Commands

Something unusual is happening--obviously, and was hoping a seasoned person might be able to help me. It looks like the .paj file has many different parts jammed into the one file I have downloaded. Not really sure how to break it up since there is no comments and seems like Pajek in general is meant to operate with a GUI.

>> G.node['f49']
{'id': '49', 'shape': '0.5000', 'x': 0.5533, 'y': 0.3766}

Was hoping to use the status of the nodes (attributes that range from 0-14). Thank you!

도움이 되었습니까?

해결책

The networkx Pajek file reader can't handle the .paj format files with extra "partition" data in it. Unfortunately it seems like it works. But obviously you are getting extra nodes and edges.

If you remove everything in the file SanJuanSur2.net starting at *Edges to the end you can read it with networkx.read_pajek().

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top