I have a file with various words, which I want to count the frequency of each word in the document and plot it.
However, my plot is not showing results.
The x-axis
must contain the words, and the y-axis
the frequency.
I am using NLTK
, NumPy
and Matplotlib
Here's my code, maybe I did something wrong
def graph():
f = open("file.txt", "r")
inputfile = f.read()
words = nltk.tokenize.word_tokenize(inputfile)
count = set(words)
dic = nltk.FreqDist(words)
FreqDist(f).plot(50, cumulative=False)
f.close()
- Given a list of words in the file
file.txt
:
southbound
stopped
travel
lane
started
around
stopped
stopped
started
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…