ego graph shell layout with less than 2 dimensions

34 views
Skip to first unread message

Matthew Kline

unread,
Aug 2, 2022, 2:35:26 PMAug 2
to networkx-discuss
Hello!
I have been working on a project where I am analyzing ego graph networks in a shell layout. I need to use to format of the shell layout but through this dimensions cannot be less than 2.  This means that the network will show immediate and secondary connections.  Does anyone know how to bypass this requirement so that only primary connections are shown? 

Thanks!

-Matt

Dan Schult

unread,
Aug 2, 2022, 3:57:28 PMAug 2
to networkx...@googlegroups.com
The nx.ego_graph() function returns the subgraph of the node of interest and its neighbors. If I understand you correctly you would like to remove the edges between the neighbors and just show the "star" shape of the primary node and the edges to its neighbors.  The easiest way would likely be to just construct a star_graph using the primary node and it's neghbors.

```
G = nx.wheel_graph(5)  # start from full graph
node = 0
H = nx.star_graph([node] + list(G[node]))
H.edges   # shows:  EdgeView([(0, 1), (0, 2), (0, 3), (0, 4)])

node = 1
H = nx.star_graph([node] + list(G[node]))
H.edges   # shows:  EdgeView([(1, 0), (1, 2), (1, 4)])
```

Matthew Kline

unread,
Aug 11, 2022, 9:56:54 AMAug 11
to networkx-discuss
I appreciate your answer.  I apologize for the delayed response I have been.

I currently have an ego graph with a shell layout using the code:


    G_sub= nx.ego_graph(G,(item),radius=1, center= True, undirected=True, distance='weight')
   
   
    # create list for nlist. This positions (item) in center of subgraph
    others = list(G_sub)
    others.remove(item)
 

    # Specify shell positioning of nodes. "Items" is centered, "others"/connected nodes will surround

    pos = nx.shell_layout(G_sub, nlist=[(item,), others],dim=2)
    for n, p in pos.items():
        G_sub.nodes[n]['pos'] = p
        



In this case, "Item" Is the center node and "others" are the connected nodes which creates the network I have attached. 

How would I go about translating this to a wheel or star graph?

Thanks so much for all of your help!!
network.PNG

Dan Schult

unread,
Aug 11, 2022, 10:01:27 PMAug 11
to networkx...@googlegroups.com
H = nx.star_graph([item] + others)  # just make a list with center node first and the "rim nodes" after that.
Reply all
Reply to author
Forward
0 new messages