I want to draw a layered graph If you can look at the graph below, it can be ordered the following way
95 85
21 31
42 52 62 22 32
13
14
I can provide hints which node in which layer goes if needed.
In the past I had similar need, but it does not work in this case : NetworkX: draw graph in layers
I tried all standard layouts and all graph_viz layouts : ‘dot’, ‘twopi’, ‘fdp’, ‘sfdp’, ‘circo’
By layered I mean where every group of nodes are on the same layer (vertical coordinates : Y)
Like I've ordered them above ...
this my first crack on it ...now i have to do the x-axis more clearly based on edges. thanks mathfux
def layered_layout(nodes, base):
nodes = np.array(nodes)
ncols = np.unique( nodes % base, return_counts=True)[1].max()
nlayers = np.unique(nodes % base).size
ys = np.linspace(0, 1, nlayers)
xs = np.linspace(0, 1, ncols)
pos = {}
for j,b in enumerate(np.unique(nodes % base)):
ixs = np.where(nodes % base == b)[0]
for i,x in enumerate(ixs) :
node = nodes[x]
pos[node] = (xs[i], ys[j])
return pos