6

I have a graph stored in an adjacency list format. I randomly select a bunch of nodes and note the number of neighbors each of them have. I now want to plot the distribution, and the way I do it right now is by manually checking if the size of the neighbor set falls into a particular bucket (I set the bucket sizes manually and this checking process results in a bunch of very ugly if-then-else statements) and then increment the frequency accordingly. I then call matplotlib and plot the graph. This entire process seems really cumbersome and not pythonic at all. It's totally doable in Excel but I'm trying to make it as programmatic as possible.

I'm sure there's a better way to do this but I couldn't find anything related to frequency plotting. Any suggestions would be awesome.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Dopey
  • 61
  • 1
  • 1
  • 2
  • 1
    Your problem is two-part and it is not clear which (if not both) part you want help with. 1) cleanly/efficiently converting an adjacency list to an edge count array. 2) plotting the edge count array as a frequency plot. If #1, please provide some more detail about the adjacency list. Is it an array, a python list, or a file? – Paul May 07 '11 at 20:26

2 Answers2

15

Is matplotlib.pyplot.hist() what you are looking for?

FMc
  • 41,963
  • 13
  • 79
  • 132
Paul
  • 42,322
  • 15
  • 106
  • 123
0

Instead of computing intervals an then plotting them, why not simply plot the density of the "the number of neighbors each of them have" you noted? Here is a great post on how to do this in Python.

Community
  • 1
  • 1
Christian O'Reilly
  • 1,864
  • 3
  • 18
  • 33