Created
September 7, 2019 17:07
-
-
Save julian-west/c2fd8efaae3f31563701010b631fbe3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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