gpt4 book ai didi

python - 我的词云缺少字符串中四个词中的三个。我如何添加缺少的单词?

转载 作者:太空宇宙 更新时间:2023-11-04 01:44:50 26 4
gpt4 key购买 nike

我正在尝试根据“嗨,你好吗”这句话创建词云。但我只得到第一个词。为什么?

代码:

#@title Bar plot of most frequent words.
from wordcloud import WordCloud,STOPWORDS
stopwords = set(STOPWORDS)
wordcloud = WordCloud(
width=800,height=800,
stopwords = stopwords,
min_font_size = 10,
background_color='white'
).generate("hi how are you")
# plot the WordCloud image
plt.figure(figsize = (8, 8), facecolor = None)
plt.imshow(wordcloud,interpolation="bilinear")
plt.axis("off")
plt.tight_layout(pad = 0)

plt.show()

输出:

enter image description here

最佳答案

在上面的 OP 代码中,stopwords 参数被设置为模块 STOPWORDS 列表。在此列表中,howareyou 都包含在内。这限制了这些词在词云中的显示。

注意,如果没有给出这个参数,它也将默认为这个列表,所以如果你想包含所有单词,你需要加载一个空列表。

关于python - 我的词云缺少字符串中四个词中的三个。我如何添加缺少的单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59293686/

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