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.

1
  • 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? Commented May 7, 2011 at 20:26

2 Answers 2

15

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.