Hi, 

> I'm new to igraph-python. My problem is that after retrieving degree 
> distribution by g.degree_distribution(), how can i plot it or write to a text 
> file?
There are many ways to do this:

1. You can get a simple visual representation on the screen using ASCII 
characters by printing the histogram:

>>> print graph.degree_distribution()
 
2. You can save the bins and counts of the histogram into a file by iterating 
over its bins:

f = open("histogram.txt")
for left, right, count in graph.degree_distribution().bins():
    print >>f, left, right, count
f.close()

This will create a file with three columns; the first containing the left side 
of the bin, the second containing the right side of the bin, the third 
containing the number of nodes in the bin. For the degree distribution, you can 
simply omit the second column.

3. If you have installed matplotlib and pylab, you can plot the bins using 
pylab as follows:

xs, ys = zip(*[(left, count) for left, _, count in 
graph.degree_distribution().bins()])
pylab.bar(xs, ys)
pylab.show()

Best,
Tamas


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

Reply via email to