igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] plot VertexClustering help


From: Tamás Nepusz
Subject: Re: [igraph] plot VertexClustering help
Date: Tue, 3 Dec 2013 16:06:34 +0100

> 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.  




reply via email to

[Prev in Thread] Current Thread [Next in Thread]