for edge in G.edges():
    if floor(edge[0] / 5.0) != floor(edge[1] / 5.0):
        if random.random() < 0.95:
            G.remove_edge(edge[0], edge[1])
nx.draw_spring(G)
py.show()
fixedpos = {(1): (0, 0), (6): (1, 1), (11): (1, 0), (16): (0, 1)}
pos = nx.spring_layout(G, fixed=list(fixedpos.keys()), pos=fixedpos)
nx.draw_networkx(G, pos=pos)
py.show()
Group vertices in clusters using NetworkX