matplotlib - python plot and powerlaw fit -


i have following list:

[6, 4, 0, 0, 0, 0, 0, 1, 3, 1, 0, 3, 3, 0, 0, 0, 0, 1, 1, 0, 0, 0, 3, 2, 3, 3, 2, 5, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 2, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, 0, 0, 0, 2, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 3, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 2, 2, 3, 2, 1, 0, 0, 0, 1, 2] 

i want plot frequency of each entity python , make powerlaw analysis on it.

but cannot figure how can plot list ylabel frequency , xlabel numbers on list.

i thought create dict frequencies , plot values of dictionary, way, cannot put numbers on xlabel.

any advice?

i think you're right dictionary:

>>> import matplotlib.pyplot plt >>> collections import counter >>> c = counter([6, 4, 0, 0, 0, 0, 0, 1, 3, 1, 0, 3, 3, 0, 0, 0, 0, 1, 1, 0, 0, 0, 3, 2, 3, 3, 2, 5, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 2, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, 0, 0, 0, 2, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 3, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 2, 2, 3, 2, 1, 0, 0, 0, 1, 2]) >>> sorted(c.items()) [(0, 50), (1, 30), (2, 9), (3, 8), (4, 1), (5, 1), (6, 1)] >>> plt.plot(*zip(*sorted(c.items())) ... ) [<matplotlib.lines.line2d object @ 0x36a9990>] >>> plt.show() 

there few pieces here of interest. zip(*sorted(c.items())) return [(0,1,2,3,4,5,6),(50,30,9,8,1,1,1)]. can unpack using * operator plt.plot sees 2 arguments -- (0,1,2,3,4,5,6) , (50,30,9,8,1,1,1). used x , y values in plotting respectively.

as fitting data, scipy of here. specifically, have @ following examples. (one of examples uses power law).


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -