5

I am using graph-tool on Python 3.5.1. I have a graph of words, with edges between words that rhyme. When I use graph-tool's draw function, it causes all the vertices to overlap if I make the vertices too large, but if they are too small, I must make the font smaller, and then it is illegible. Is there any way of setting a minimum edge length or forcing the vertices not to overlap?

Code sample:

import graph_tool.all as gt

G = gt.load_graph("G.gt")
gt.graph_draw(G, vertex_text=G.vertex_properties.word, vertex_font_size=10, output_size=(1000, 1000), output="G.png", vertexsize=10)

See image here

2 Answers 2

1

Have you tried using graphviz_draw? It has an overlap setting where you can tell the software to prevent vertices from touching. The syntax is different for the function so you may need to do some searching but if you look at the graphviz documentation linked in the graph-tool manual you should be able to find all your attributes (http://www.graphviz.org/doc/info/attrs.html ).

1

My guess is that you can't change the relative size of the edges, but you can change the font and the vertex sizes. So at the moment I'm shrinking the vertices and displaying the text outside them. Works beautifully.

import cairo
from graph_tool.draw import graph_draw, prop_to_size

graph_draw(g, 
       edge_pen_width=1,
       vertex_text=g.vp.my_property, 
       vertex_aspect=1, 
       vertex_text_position=1, 
       vertex_text_color='black',
       vertex_font_family='sans',
       vertex_font_size=11,
       vertex_font_weight=cairo.FONT_WEIGHT_NORMAL,
       vertex_color=None,
       vertex_size=5
      )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.