I`m looking for the way to specify precise lengths of edges in graph to get appropriate drawing. I`ve tried to make it via edge properties:
import numpy as np
import graph_tool.all as gt
tree = gt.Graph()
# ddmatrix is a symmetric adjacency matrix
eprop = tree.new_edge_property("string")
for i in range(ddmatrix.shape[0]):
for j in range(i):
if ddmatrix[j, i] != 0:
e = tree.add_edge(i, j)
eprop[e] = ddmatrix[j, i]
tree.edge_properties["weight"] = eprop
gt.graph_draw(tree, pos=gt.radial_tree_layout(tree, 0), ...)
But it seems to me that there is no argument in graph-tool drawing function with radial tree layout which can specify edges length graph-tool draw
I`ve found that weight of edge can influence of edges length in arf layout (at least it seemed to me so...), but it didn`t make lengths ratio exact like in input and makes a mess in vertex placement (with intersected edges) more often than tree layout.
Is there some way to draw graph image with specified distances between vertices, which are equal to edges weights? It`s interesting for me in general and in particular I have a case, where desired graph can be built (representation of tree with distances between adjacent nodes):
[[ 0. 1.25 0. 0. 2.25]
[ 1.25 0. 1. 1. 0. ]
[ 0. 1. 0. 0. 0. ]
[ 0. 1. 0. 0. 0. ]
[ 2.25 0. 0. 0. 0. ]]
And finally, I wonder how should be rewritten this fragment to obtain weighted graph with edge weights as a property given adjacency matrix (I`ve tried recipe from there Create a weighted graph from an adjacency matrix but it doesn`t save edges weights in my case):
eprop = tree.new_edge_property("double")
tree.add_edge_list(np.transpose(ddmatrix.nonzero()), eprop)
tree.edge_properties["weight"] = eprop
I`m sorry if this question has been discussed, but I didn`t find solution yet. Anyway thank you.