我的词云缺少字符串中四个词中的三个。我如何添加缺少的单词?
My word cloud is missing three out of the four words in my string. How do I add the words it's missing?
我正在尝试根据句子 "hi how are you" 创建词云。但我只得到第一个词。为什么?
代码:
#@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()
输出:
在上面的 OP 代码中,stopwords
参数被设置为模块 STOPWORDS
列表。在这个列表中,how
、are
、you
都包括在内。这限制了这些词在词云中的显示。
注意,如果没有给出这个参数,它也将默认为这个列表,所以如果你想包含所有的单词,你需要加载一个空列表。
hi
、are
和 you
包含在 STOPWORDS
.
中
如果你想保留这些特定的词,你需要从 STOPWORDS
中过滤掉它们
喜欢:
from wordcloud import WordCloud, STOPWORDS
stopwords = {word for word in STOPWORDS if word not in {'how', 'are', 'you'}}
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()
我正在尝试根据句子 "hi how are you" 创建词云。但我只得到第一个词。为什么?
代码:
#@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()
输出:
在上面的 OP 代码中,stopwords
参数被设置为模块 STOPWORDS
列表。在这个列表中,how
、are
、you
都包括在内。这限制了这些词在词云中的显示。
注意,如果没有给出这个参数,它也将默认为这个列表,所以如果你想包含所有的单词,你需要加载一个空列表。
hi
、are
和 you
包含在 STOPWORDS
.
如果你想保留这些特定的词,你需要从 STOPWORDS
喜欢:
from wordcloud import WordCloud, STOPWORDS
stopwords = {word for word in STOPWORDS if word not in {'how', 'are', 'you'}}
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()