How to draw multiple subplots on cairo surface?

Hi, everyone,

I have started exploring options of plotting multiple diagrams in Python in a similar manner like matplotlib does. My first attempt is to write a script that immitates behaviour of subplots like in this example

#Add title and legend to igraph plots
from igraph import Graph, Plot
from igraph.drawing.text import TextDrawer
import cairo

shape = (4, 4)
colsep, rowsep = 40, 40
width, height = 250, 250

# Construct the plot
plot = Plot("plot.png", bbox=(4*width, 4*height), background="white")

# Create the graph and add it to the plot
for i in range(shape[0]):
    for j in range(shape[1]):
        n, radius = 20 * (1+i), 0.2 * (j+1)
        g = Graph.GRG(n, radius)
        # g['vertex_size'] = 10
        # g['vertex_label_size'] = 6
        plot.add(g, bbox=(colsep/2 + width*i, rowsep/2 + height*j, -colsep/2 + width*(i+1), -rowsep/2 + height*(j+1)))

        # Make the plot draw itself on the Cairo surface

        ##Grab the surface, construct a drawing context, TextDrawer on surface
        # ctx = cairo.Context(plot.surface)
        # ctx.set_font_size(36)
        # drawer = TextDrawer(ctx, f'Graph.GRG({n}, {radius})', halign=TextDrawer.CENTER)
        # drawer.draw_at(width*i, 36 + height*j, width=200)

At the moment it works fine:

But I’d also like to customize it. Can you help me to answer these questions?

  1. How to add title names over each of diagrams. I was trying to add cairo context in commented lines but then it displays only one (title).
  2. How to change features of plot like size of vertices or labels? I didn’t succeed after my attempt to change attributes of graph.
  3. Is there a way to constructs axis an tick labels on the surface? Basically, g.layout().coords are 2D coords that varies between 0 and 1
  4. Is there a simple, not mathematical way to extract positions of several plots, like layout(matrix(1:16, nr=4, byrow=TRUE)) in R language?