Python 在wordcloud中向stopwords添加单词不起作用

Python 在wordcloud中向stopwords添加单词不起作用,python,numpy,word-cloud,Python,Numpy,Word Cloud,我想在wordcloud中添加一些stopwords,但结果图像显示了我添加到stopwords中的确切单词。我做错了什么?如何将该单词添加到stopwords中 from wordcloud import STOPWORDS as EN_STOPWORDS from wordcloud import ImageColorGenerator from stopword_persian import stopword_persian as STOPWORDS from wordcloud_fa i

我想在wordcloud中添加一些stopwords,但结果图像显示了我添加到stopwords中的确切单词。我做错了什么?如何将该单词添加到stopwords中

from wordcloud import STOPWORDS as EN_STOPWORDS
from wordcloud import ImageColorGenerator
from stopword_persian import stopword_persian as STOPWORDS
from wordcloud_fa import WordCloudFa


# Add another stopword
STOPWORDS.add('ميساخته')
stopwords = STOPWORDS.union(EN_STOPWORDS)


# Generate a word cloud image

wordcloud = WordCloudFa(
    persian_normalize=True,
    include_numbers=True,
    max_words=300,
    stopwords=stopwords,
    margin=0,
    width=3000,
    height=3000,
    min_font_size=1,
    max_font_size=500,
    random_state=True,
    background_color="black",
    mask=twitter_mask
).generate(text)


你可以这样做

导入matplotlib.pyplot作为plt
导入nltk#自然语言工具包
nltk.download('stopwords'))
从nltk.corpus导入stopwords#以去除stopwords
从wordcloud导入wordcloud、STOPWORDS、ImageColorGenerator#以创建单词云
从带WordCloud的PIL导入图像#枕头到图像处理
text='新的停止词不适合此文本。'
#添加停止词
stop\u words=stopwords.words('en')
new_stopwors=['new','stop','words']
停止单词。扩展(新的停止单词)
停止单词=设置(停止单词)
#摆脱停止语
clean_text=[文本中的逐字逐句。如果单词不在stop_words中,则拆分()
#将列表转换为字符串
text=''.join([str(elem)表示干净文本中的elem])
#生成wordcloud
wordcloud=wordcloud(背景颜色=“黑色”)。生成(文本)
#显示生成的图像:
plt.图(figsize=(15,10))
plt.imshow(wordcloud,插值=‘双线性’)
plt.轴(“关闭”)
plt.show()

如果您想了解更多有关插值的信息,这里有一个有用的方法。

首先,您可以检查
print(stopwords)