igraph plot for multiple layers partition does not return expected output

Thanks for the detail explanation @vtraag

Maybe unintended, but I notice there are some typo.

  • Missing (

Should be

G_layers, G_interslice, G = la.time_slices_to_layers([G1, G2, G3], interslice_weight=1e-1,
                                                     slice_attr='slice', vertex_id_attr='name')
  • Oulier > edge_type_attr='type', weight_attr='weight')

Should be


interslice_partition = la.CPMVertexPartition(G_interslice, resolution_parameter=0,
                                             node_sizes='node_size', weights='weight')

Amending these two lines may successfully produce the graph as shown above

Thanks for introducing Formula. This indeed an elegant way of constructing a graph.

But I believe, the connection to reproduce the original diagram should be


G1 = ig.Graph.Formula('A-B-D-C-A, D-E-G-F-D')

For future reader who might be interested with input framed from numpy array, below is the complete code based on @vtraag suggestion.
Please note, in the code below we used id instead of name


import leidenalg as la
import igraph as ig
import numpy as np

A1 = np.array ( [[0., 0., 0., 0., 0, 0, 0], [5., 0., 0., 0., 0, 0, 0], [1., 0., 0., 0., 0, 0, 0],
                 [0., 1., 2., 0., 0, 0, 0], [0., 0., 0., 1., 0, 0, 0], [0., 0., 0., 1., 0, 0, 0],
                 [0., 0., 0., 0., 1, 1, 0]] )

A2 = np.array ( [[0., 0., 0., 0., 0, 0, 0], [5., 0., 0., 0., 0, 0, 0], [1., 0., 0., 0., 0, 0, 0],
                 [0., 1., 2., 0., 0, 0, 0], [0., 0., 0., 1., 0, 0, 0], [0., 0., 1., 1., 0, 0, 0],
                 [0., 0., 0., 0., 1, 1, 0]] )

A3 = np.array ( [[0., 0., 0., 0., 0, 0, 0], [0., 0., 0., 0., 0, 0, 0], [0., 0., 0., 0., 0, 0, 0],
                 [0., 1., 2., 0., 0, 0, 0], [0., 0., 0., 1., 0, 0, 0], [0., 0., 0., 1., 0, 0, 0],
                 [0., 0., 0., 0., 1, 1, 0]] )

G_1 = ig.Graph.Weighted_Adjacency ( A1.tolist () )
G_2 = ig.Graph.Weighted_Adjacency ( A2.tolist () )
G_3 = ig.Graph.Weighted_Adjacency ( A3.tolist () )
G_1.vs ['id'] = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
G_2.vs ['id'] = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
G_3.vs ['id'] = ['A', 'B', 'C', 'D', 'E', 'F', 'G']

# Convert from slices to layers
# Note here, the slice', vertex_id_attr is assigned to `id` since we define it as id at the previous step
G_layers, G_interslice, G = la.time_slices_to_layers([G_1, G_2, G_3], interslice_weight=1e-1,
                                                     slice_attr='slice', vertex_id_attr='id',
           edge_type_attr='type', weight_attr='weight')
# Create partitions
gamma = 0.3
partitions = [la.CPMVertexPartition(H, node_sizes='node_size',weights='weight',
                                    resolution_parameter=gamma) for H in G_layers]
interslice_partition = la.CPMVertexPartition(G_interslice, resolution_parameter=0,
                                             node_sizes='node_size', weights='weight')


# Detect communities
optimiser = la.Optimiser()
optimiser.set_rng_seed(11)
diff = optimiser.optimise_partition_multiplex(partitions + [interslice_partition])


# Plot network
# Note here, the`v` is assigned to `id` since we define it as id at the previous step
partition_all = ig.VertexClustering(G, partitions[0].membership)
ig.plot(partition_all,
        vertex_label = [f'{v["id"]}-{v["slice"]}' for v in G.vs])

Which produced

For visual learner, I had manually label the edge. The label color black, blue and red represent the slice G_1, G_2, and G_3, respectively.