Add nodes to a fixed backbone when drawing a networkx graph with graphviz, some of the larger nodes are ending up crammed together -


i have created graph using networkx. drawing graph using graphviz, these lines of code:

pos = nx.graphviz_layout(g2, prog='neato', args='-goverlap=prism')  plt.figure(figsize=(10, 14))  nx.draw(g2, pos, node_size=sizes, alpha=1, nodelist=nodes, node_color=colors, with_labels=true, labels=labeldict, font_size=8) 

the graph consists of "backbone" of few larger nodes, attached few hundred smaller nodes.

i have used args='-goverlap=prism' (in first line of code above) space out graph, has created problem. matters more larger nodes spaced out, but, because of how many small nodes there are, of larger nodes ending crammed together.

my thoughts on solution generate graph larger nodes ensure spaced, add smaller nodes graph without changing layout of original nodes. have done research, , seems tricky add new nodes without changing old ones in graphviz. possible "pin" nodes, unsure of how within networkx.

this graph looks like:

enter image description here

your thoughts seem reasonable. following code generates graph, assigns initial position nodes 1 , 2, uses nx.spring_layout assign positions of them. allow node 2 move, node 1 stays fixed.

import networkx nx g=nx.path_graph(6) originalpos = {1:(0,0), 2:(1,0)} newpos = nx.spring_layout(g, pos=originalpos, fixed=[1]) newpos > {0: array([-0.39442754, -0.35733777]),  1: array([ 0.,  0.]),  2: array([ 0.44050048,  0.3734393 ]),  3: array([ 0.8658906 ,  0.80306291]),  4: array([ 1.21367619,  1.27878715]),  5: array([ 1.45676553,  1.72154196])} 

for case positions backbone , use nodes fixed list.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -