I want to draw a plot with the y axis in a 'logarithmic scale'. However, it pops up "
NameError: global name 'log' is not defined ". Does anyone know how to import log in this case? Thanks indeed.
>>> 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]]])
index.extend([i+1])
pylab.plot(index, log(y),'-bo')
pylab.title('zipf law')
pylab.xlabel('word rank')
pylab.ylabel('word frequency')
pylab.show()
>>> zif(text)
Traceback (most recent call last):
File "<pyshell#141>", line 1, in <module>
zif(text)
File "<pyshell#140>", line 12, in zif
pylab.plot(index, log(y),'-bo')
NameError: global name 'log' is not defined