gpt4 book ai didi

python - 如何保存 nltk FreqDist 图?

转载 作者:行者123 更新时间:2023-12-01 01:30:37 26 4
gpt4 key购买 nike

我尝试了不同的方法来保存我的情节,但我尝试过的每件事都出现了空白图像,而且我目前还没有没有想法。有其他可以解决此问题的建议吗?代码示例如下。

word_frequency = nltk.FreqDist(merged_lemmatizedTokens) #obtains frequency distribution for each token
print("\nMost frequent top-10 words: ", word_frequency.most_common(10))
word_frequency.plot(10, title='Top 10 Most Common Words in Corpus')
plt.savefig('img_top10_common.png')

最佳答案

当我第一次初始化图形对象,然后调用绘图函数并最终保存图形对象时,我能够保存 NLTK FreqDist 图。

import matplotlib.pyplot as plt
from nltk.probability import FreqDist

fig = plt.figure(figsize = (10,4))
plt.gcf().subplots_adjust(bottom=0.15) # to avoid x-ticks cut-off
fdist = FreqDist(merged_lemmatizedTokens)
fdist.plot(10, cumulative=False)
plt.show()
fig.savefig('freqDist.png', bbox_inches = "tight")

关于python - 如何保存 nltk FreqDist 图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52908305/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com