Frequency distribution in python

I have a graph stored in adjacency list format. I randomly select a bunch of nodes and notice the number of neighbors, each of which has. Now I want to build a distribution, and the way I'm doing it right now is to manually check if the size of the neighboring set falls into a specific bucket (I set the bucket sizes manually, and this verification process leads to a bunch of very ugly if-then-else ), and then increase the frequency accordingly. Then I call matplotlib and plot the graph. This whole process seems really cumbersome, and not generally pythonic. This is fully doable in Excel, but I try to make it as programmatic as possible.

I am sure that there is a better way to do this, but I could not find anything related to frequency construction. Any suggestions would be great.

+6
source share
2 answers

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

+15
source

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

0
source

Source: https://habr.com/ru/post/887527/


All Articles