R04: (423.0, 234.0)
R17: (207.0, 162.0)
R14: (423.0, 162.0)
R13: (639.0, 162.0)
R11: (279.0, 90.0)
R16: (117.0, 90.0)
R07: (351.0, 90.0)
R01: (423.0, 90.0)
R09: (639.0, 90.0)
R15: (495.0, 90.0)
R05: (711.0, 90.0)
R03: (207.0, 90.0)
R12: (567.0, 90.0)
R00: (387.0, 18.0)
R19: (27.0, 18.0)
R18: (243.0, 18.0)
R10: (99.0, 18.0)
R02: (171.0, 18.0)
R06: (567.0, 18.0)
R08: (315.0, 18.0)
pos = nx.drawing.nx_agraph.graphviz_layout(R_net, prog='dot')
new_pos = nx.drawing.layout.rescale_layout(np.array([[v[0], v[1]] for v in pos.values()]), 1)
new_pos = {k: tuple(v) for k, v in zip(pos.keys(), new_pos)}
for k, v in new_pos.items():
print("{}: {}".format(k, v))
R04: (0.16883116883116883, 0.43636363636363634)
R17: (-0.45454545454545453, 0.22857142857142859)
R14: (0.16883116883116883, 0.22857142857142859)
R13: (0.79220779220779225, 0.22857142857142859)
R11: (-0.24675324675324675, 0.020779220779220786)
R16: (-0.7142857142857143, 0.020779220779220786)
R07: (-0.03896103896103896, 0.020779220779220786)
R01: (0.16883116883116883, 0.020779220779220786)
R09: (0.79220779220779225, 0.020779220779220786)
R15: (0.37662337662337664, 0.020779220779220786)
R05: (1.0, 0.020779220779220786)
R03: (-0.45454545454545453, 0.020779220779220786)
R12: (0.58441558441558439, 0.020779220779220786)
R00: (0.064935064935064929, -0.18701298701298699)
R19: (-0.97402597402597402, -0.18701298701298699)
R18: (-0.35064935064935066, -0.18701298701298699)
R10: (-0.76623376623376627, -0.18701298701298699)
R02: (-0.55844155844155841, -0.18701298701298699)
R06: (0.58441558441558439, -0.18701298701298699)
R08: (-0.14285714285714285, -0.18701298701298699)
I am using `networkx.drawing.layout.rescale_layout`.
However, in this function, input is fixed to `np.array`.
In fact, other layouts (`nx.spring_layout`, `nx.spectral_layout`, etc.) return a dictionary (key: node label, value: pos tuple (x, y)).
So, for `networkx.drawing.layout.rescale_layout`, I think it would be useful to change the input to dictionary (key: node label, value: pos tuple (x, y)).
To change to the code:
I think this case is more versatile and I would like to ask you what you think.
def rescale_layout(pos, scale=1):
pos_v = np.array([[v[0], v[1]] for v in pos.values()])
lim = 0 # max coordinate for all axes
for i in range(pos_v.shape[1]):
pos_v[:, i] -= pos_v[:, i].mean()
lim = max(abs(pos_v[:, i]).max(), lim)
# rescale to (-scale, scale) in all directions, preserves aspect
if lim > 0:
for i in range(pos_v.shape[1]):
pos_v[:, i] *= scale / lim
return {k: tuple(v) for k, v in zip(pos.keys(), pos_v)}
댓글남기기