I'm trying to create a bipartite graph that contains an isolated node, however nx.bipartite_layout connects it to other nodes, nevertheless. How can I prevent this from happening?
I tried to restructure the graph in many ways but it only works well when all the nodes have at least one edge.
You can use this code to reproduce the problem:
G = nx.dense_gnm_random_graph(6, 9, 5)
G.remove_edges_from([(3,1), (3,4), (3,5), (4,5)])
print(G.edges())
# prints [(0, 2), (0, 4), (2, 3), (2, 4), (2, 5)]
nx.draw(G, pos=nx.bipartite_layout(G, list(G.nodes())[:len(G.nodes())//2]), node_color='gray',with_labels=True)
# produces a graph with node 1 tied to 0 and 2 (even though it is an isolate)
The actual output is supposed to be a graph in which 1 is still isolated.