NetworkX offers G.subgraph(node_list)
but when I plot it, it retains the node positions in the original full multipartite graph which is messy. I want the subgraph to be recalculated as a new plot (relatively centered) still retaining its multipartite layers but cleaner in terms of nodes vertical position. I'm using hvplot for displaying the graph using hvplot.networkx as hvnx
. Additionally with this subplot from hvplot, there are some strange lines coming from the graph which don't show when i just use nx.draw(G.subgraph(node_list), pos).
Thanks.
Solved both the problems.
hvnx
output by converting the graph to undirected.GU = G.subgraph(node_list).to_undirected()
pos = nx.multipartite_layout(GU, subset_key="layer")
hvnx.draw(GU, pos)