I have python code to extract node positions, beizier points, and blocks after running the NSBM and export them. The exported data is later loaded by a custom JavaScript code that creates an interactive plot.
However, I’m facing a couple of challenges:
Extracting Node Colors: I really like the colors that Graph-tool generates in the plot, but I haven’t found a way to extract them for reuse. Currently, I’m generating random colors, but I’d prefer to keep the ones Graph-tool provides. Is there a workaround to access and export these colors?
Node Position Rotation/Reflection: The node positions seem to be rotated or reflected compared to the original Graph-tool plot. Is there a specific formula I can use to map these positions correctly and ensure they match the layout from Graph-tool?
graph-tool
my result
my code
state_3 = minimize_nested_blockmodel_dl(g3gt, state_args=dict(overlap=False))
spos0, tg, tpos =state_3.draw(output="text3.png", beta=0.9)
cts = gt.draw.get_hierarchy_control_points(g3gt, tg, tpos, beta=0.9)
pos = g3gt.own_property(tpos)
pos = np.array(list(pos))
postg = np.array(list(tg.own_property(tpos)))
edgePos = list(cts)
dataEdge = {'beizer':[], 's':[], 't':[],}
nodes_graph = []
for b, e in zip(edgePos, g3gt.edges()):
s = g3gt.vertex_index[e.source()]
t = g3gt.vertex_index[e.target()]
nodes_graph+=[s,t]
dataEdge['beizer'].append(list(b))
dataEdge['s'].append(s)
dataEdge['t'].append(t)
dfEdge = pd.DataFrame(data=dataEdge)
numNodes = pos.shape[0]
numNodesBlocks = postg.shape[0] - numNodes
# memberships
st = [list(list(b)) for b in state_3.get_bs()]
sizes = [len(l) for l in st[1:len(st)]]
sizes0 = [0]+[val + np.sum(sizes[i+1:len(sizes)]) for i, val in enumerate(sizes)][::-1]
nodeIds = [
list(range(int(sizes0[i])+1, int(s)+1))[::-1]
for i, s in enumerate(sizes0[1:len(sizes0)])
][::-1]
nodeHierarchy0 = {}
for k, nodeLevel in enumerate(st[0]):
nodeHierarchy0[k] = [nodeIds[0][nodeLevel]]
for i in range(1, len(st)-1):
newLevel = st[i][nodeLevel]
nodeHierarchy0[k].append(nodeIds[i][newLevel])
nodeLevel = newLevel
blocks = [nodeHierarchy0[k] for k in range(len(pos))]