>>> def zif(text):
fdist = nltk.FreqDist(text)
import pylab
word = fdist.keys()
x = []
y = []
index = []
for i in range(0,len(set(text)),1):
x.extend(word[i:i+1])
y.extend('fdist[word[i:i+1]]')
index.extend('i+1')
pylab.plot(index, y,'b')
pylab.title('zipf law')
pylab.xlabel('word rank')
pylab.ylabel('word frequency')
pylab.show()
>>> zif(text)
Traceback (most recent call last):
File "<pyshell#35>", line 1, in <module>
zif(text)
File "<pyshell#34>", line 12, in zif
pylab.plot(index, y,'b')
File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 2458, in plot
ret = ax.plot(*args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 3848, in plot
for line in self._get_lines(*args, **kwargs):
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 323, in _grab_next_args
for seg in self._plot_args(remaining, kwargs):
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 300, in _plot_args
x, y = self._xy_from_xy(x, y)
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 240, in _xy_from_xy
raise ValueError("x and y must have same first dimension")
ValueError: x and y must have same first dimension
Thanks indeed.