> This is my solution in R, but it should be doable in Python along
> similar lines:

I’ll try to translate this line by line to Python. (Untested, but shows the 
general idea). It is assumed that g2 is the original graph, g1 is the community 
graph and contracted_community is the community object returned by the 
community detection algorithm. (It must be a VertexClustering).
  
> # Layout for community graph
> outer.layout <- layout.auto(g1) * vcount(g1)

outer_layout = g1.layout(“auto”)
outer_layout.scale(g1.vcount())
  
> # Create empty layout for orignal graph
> inner.layout <- matrix(nrow=vcount(g2), ncol=2)
> r <- 2.9

inner_layout = Layout([(0, 0) for _ in xrange(g2.vcount())])
r = 2.9

> for (comm in 1:length(contracted.community)) {
> # IDs of community members in outer graph
> vids <- which(membership(contracted.community) == comm)
> # calculate layout for community
> comm.graph <- induced.subgraph(g2, vids)
> comm.layout <- layout.auto(comm.graph)
> # normalize community layout into corresponding outer graph vertex
> bbox <- outer.layout[comm,] + c(-r, -r, r, r)
> comm.layout <- layout.norm(comm.layout, xmin=bbox[1], ymin=bbox[2],
> xmax=bbox[3], ymax=bbox[4])
> inner.layout[vids,] <- comm.layout
> }

for comm, vids in enumerate(contracted_community):
    comm_graph = g2.induced_subgraph(vids)
    comm_layout = g2.layout(“auto”)
    cx, cy = outer_layout[comm]
    bbox = (cx-r, cy-r, cx+r, cy+r)
    comm_layout.fit_into(bbox)
    for vid, coords in izip(vids, comm_layout):
        inner_layout[vid] = coords

> plot(contracted.community, g2, layout=inner.layout,
> edge.color=c("black", "gray")[crossing(contracted.community,
> g2)+1])

plot(contracted_community, layout=inner_layout)
  
T.  


_______________________________________________
igraph-help mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/igraph-help

Reply via email to