[Top][All Lists]

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

Re: [igraph] how to plot histogram in igraph-python

From: Tamás Nepusz
Subject: Re: [igraph] how to plot histogram in igraph-python
Date: Tue, 24 Jul 2012 11:13:42 +0200


> 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

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 
pylab.bar(xs, ys)


reply via email to

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