thanks Tamas. great help. Regards Zhang Tianyou
Senior Research Engineer, Computing Science Department Institute of High Performance Computing ________________________________________ From: [email protected] [[email protected]] On Behalf Of Tamás Nepusz [[email protected]] Sent: Tuesday, July 24, 2012 5:13 PM To: Help for igraph users Subject: Re: [igraph] how to plot histogram in igraph-python 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 IHPC Values :: Impact :: Honesty :: Performance :: Co-operation This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. _______________________________________________ igraph-help mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/igraph-help
