不同地块重叠
Different plots are overlapped
我正在使用 matplotlib 和 nltk 绘制不同作者的频率分布,但似乎在图中绘制了两个图。如何通过为作者姓名频率分布创建另一个单独的图来解决此问题?
这是我的一些代码:
# 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)
你应该考虑使用子图来绘制它。我想你的 fdist
plot 会将它添加到你所看到的当前存在的任何轴实例中。它的格式应类似于以下方式:
fig = plt.figure()
ax = fig.add_subplot(121)
# Your first plot stuff here
ax = fig.add_subplot(122)
# Your second plot here
或者,如果您希望绘图真正独立,则使用 plt.figure()
命令创建一个新的图形实例。当您使用 plt.show()
命令时,它将显示所有打开的图形实例。
我正在使用 matplotlib 和 nltk 绘制不同作者的频率分布,但似乎在图中绘制了两个图。如何通过为作者姓名频率分布创建另一个单独的图来解决此问题?
这是我的一些代码:
# 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)
你应该考虑使用子图来绘制它。我想你的 fdist
plot 会将它添加到你所看到的当前存在的任何轴实例中。它的格式应类似于以下方式:
fig = plt.figure()
ax = fig.add_subplot(121)
# Your first plot stuff here
ax = fig.add_subplot(122)
# Your second plot here
或者,如果您希望绘图真正独立,则使用 plt.figure()
命令创建一个新的图形实例。当您使用 plt.show()
命令时,它将显示所有打开的图形实例。