import re import matplotlib.pyplot as plt import numpy as np with open('testi/collodi_pinocchio.txt', mode='r', encoding='iso-8859-1') as f: testo = f.read() testo=testo[1704:] testo=re.sub("'","' ", testo) testo=re.sub('[\.,;:\-?!]{1}','',testo) testo=testo.lower() testo=testo.split() fd=[testo.count(i) for i in set(testo)] fd.sort(reverse=True) V=len(set(testo)) fig=plt.figure() ax=fig.add_subplot(1,1,1) ax.set_xscale('log') ax.set_yscale('log') ax.plot(range(1,V+1),fd, 'b.') x=np.arange(1,V+1) y=5850.7/(x**1.03372) ax.plot(x,y, 'r-') plt.show()