4

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.

Arleg
  • 735
  • 9
  • 13
  • I would rather make the distance inversely proportional to the edge weight instead of directly proportional. Why would you draw vertices far apart when they are strongly connected? – Peaceful Nov 18 '17 at 01:40
  • @Peaceful in my case weight of edge denote distance between adjacent vertex, but you are right - we can inverse every weight and after this make distance inversely proportional to edge weight. Nevertheless how to specify using weights or inverse weights as length? – Arleg Nov 18 '17 at 06:21
  • Arbitrary edge lengths are not possible even in principle because of the geometrical constraints. – Peaceful Aug 15 '18 at 09:38
  • @Peaceful you are right, but in this case these lengths are possible, because they were computed with the purpose to be drawn. I've a matrix with distances between nodes appropriate to draw a phylogenetic tree. – Arleg Sep 05 '18 at 15:51

0 Answers0