Skip to content

Instantly share code, notes, and snippets.

@julian-west
Created September 7, 2019 17:07
Show Gist options
  • Save julian-west/c2fd8efaae3f31563701010b631fbe3c to your computer and use it in GitHub Desktop.
Save julian-west/c2fd8efaae3f31563701010b631fbe3c to your computer and use it in GitHub Desktop.
def get_coordinates(G=mst):
"""Returns the positions of nodes and edges in a format for Plotly to draw the network"""
# get list of node positions
pos = nx.fruchterman_reingold_layout(mst)
Xnodes = [pos[n][0] for n in mst.nodes()]
Ynodes = [pos[n][1] for n in mst.nodes()]
Xedges = []
Yedges = []
for e in mst.edges():
# x coordinates of the nodes defining the edge e
Xedges.extend([pos[e[0]][0], pos[e[1]][0], None])
Yedges.extend([pos[e[0]][1], pos[e[1]][1], None])
return Xnodes, Ynodes, Xedges, Yedges
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment