def plot_word_frequency(df, words, category):
plt.figure()
allwords = df['lines'].str.cat(sep=' ')
allwords = allwords.split()
allwords = [word.lower() for word in allwords]
allwords = np.array(allwords)
indices = []
for word in words:
new_indices = np.where(allwords == word)
for index in new_indices[0]:
indices.append(index)
sns.distplot(indices, rug=True, hist=False)
plt.xlim(0, len(allwords))
plt.ylabel("{category} word frequency".format(category=category))
plt.xlabel("Time (words)")
plt.title("{category} words over time".format(category=category),
loc='left')
plt.savefig("../plots/{category}_frequency".format(category=category))
评论列表
文章目录