不同地块重叠

时间:2019-12-26 18:49:41

标签: python matplotlib nltk

我正在使用matplotlib和nltk绘制不同作者的频率分布,但似乎在该图中绘制了两个图。如何通过为作者名称freq dist创建另一个单独的图来解决此问题?

这是我的一些代码:

# Visualizing the # of data sets being posted every year from 2002 to 2019
num_bins = 18
n, bins, patches = plt.hist(year_list, num_bins, facecolor='blue', alpha=0.5)
plt.xlabel('Years')
plt.ylabel('# of Sets')
plt.title(r'Number of Published Data Sets from 2002 - 2019')
plt.subplots_adjust(left=0.15)
# plt.show()


from nltk.tokenize import word_tokenize
from nltk.probability import FreqDist


author_str = "".join(author_list)
fdist = FreqDist()
for word in word_tokenize(author_str):
    fdist[word.lower()] += 1
fdist.plot(10)

1 个答案:

答案 0 :(得分:2)

您应该考虑使用子图进行绘制。我想像您看到的那样,您的fdist图将其添加到当前存在的任何轴实例中。格式应类似于以下方式:

fig = plt.figure()

ax = fig.add_subplot(121)

# Your first plot stuff here

ax = fig.add_subplot(122)

# Your second plot here

签出subplots examples here.

或者,如果您希望将图真正分开,则使用plt.figure()命令创建一个新的图形实例。当您使用plt.show()命令时,它将显示所有打开的图形实例。