【发布时间】:2018-10-20 22:33:14
【问题描述】:
我一直在关注可在此处找到的样式学教程 (programminghistorian.com)。这使用 matplotlib 来绘制一些文本的频率分布。相关代码如下:
for author in authors:
tokens = nltk.word_tokenize(federalist_by_author[author])
# Filter out punctuation
federalist_by_author_tokens[author] = ([token for token in tokens
if any(c.isalpha() for c in token)])
# Get a distribution of token lengths
token_lengths = [len(token) for token in federalist_by_author_tokens[author]]
federalist_by_author_length_distributions[author] = nltk.FreqDist(token_lengths)
federalist_by_author_length_distributions[author].plot(15, title=author)
不幸的是,尽我所能,我似乎无法将这些分布覆盖到同一个 pyplot 上 - 使用此代码只会为每个作者一次打开一个新图,而不是通常的 matplotlib 'plt .plot()' 将它们添加到同一个 pyplot 的行为,这是我想要的。
关于如何做到这一点的任何想法?
【问题讨论】:
标签: python matplotlib nltk