Search code examples
cairograph-visualizationgraph-tool

How to add title to graph_tool plot?


I'm using graph_tool to draw some graphs, and I don't see an obvious way to add a title to the output image.

If it is possible, how do I add a title?

The code I have right now draws a nice-looking graph, and I have added annotations to the vertices. But I haven't found a way to annotate the graph as a whole (like a title).

import graph_tool as gt

def draw_graph(g:gt.Graph):
  ebet = gt.centrality.betweenness(g)[1]
  pos = gt.draw.arf_layout(g)
  gt.draw.graph_draw(
    g,
    pos=pos,
    vertex_text=g.vertex_index,
    edge_color=ebet,
    vertex_size=gt.draw.prop_to_size(g.vertex_properties['size'], ma=50,log=False, power=1),
    # vertex_fill_color=g.vertex_properties['size'],
    output='tiny.pdf')

Solution

  • Graph-tool is not a full-fledged plot library, it focuses only on drawing graphs. To display titles, axes, legends, etc, it should be used together with matplotlib, as explained here: https://graph-tool.skewed.de/static/doc/demos/matplotlib/matplotlib.html