python - how can i show igraph outputs? -
this simple question. i'm new python appreciate help!
in codes put below, how can show output instead of memory object?
graph.clusters(g) out[106]: <igraph.clustering.vertexclustering @ 0x1187659d0> graph.community_edge_betweenness(g, clusters=none, directed=true, weights=none) out[107]: <igraph.clustering.vertexdendrogram @ 0x118765d90>
it depends want show? let's take example:
import igraph g = igraph.graph.barabasi(n = 20, m = 3) c = g.clusters()
print()
in python calls __str__()
method of object, converts human readable, in case of vertexclustering
, each row represents cluster (cluster id in square brackets), , vertex ids belonging cluster listed. first line gives simple description:
>>> print(c) clustering 20 elements , 1 clusters [0] 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
then, can access members of each cluster list of vertex ids this:
>>> c[0] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
in case of vertexdendrogram
objects, igraph's print method prints nice text dendrogram:
>>> f = g.community_fastgreedy() >>> print(f) dendrogram, 20 elements, 19 merges 7 3 14 10 5 16 1 0 9 8 6 2 4 18 12 13 19 15 17 11 | | | | | | | | | | | | | | | | | | | | `-' | `--' | | | | `-' | `-' `--' | | `--' | | | | | | | | | | | | | | `--' | | `-' | `--' | | | `---' | | | | | | | | | | | | `---' | | | | `----' | | | | | | | | `-----' `----' | `----' | | | | | | | `------' `---------' | | | `-------------' | | | `----------------------'
finally, can show result using igraph's nice plotting capabilities:
i = g.community_infomap() colors = ["#e41a1c", "#377eb8", "#4daf4a", "#984ea3", "#ff7f00"] g.vs['color'] = [none] clid, cluster in enumerate(i): member in cluster: g.vs[member]['color'] = colors[clid] g.vs['frame_width'] = 0 igraph.plot(g)
here colored vertices cluster (community) membership:
Comments
Post a Comment