我使用 python 制作了一个词云,我想查看词云中的单词,如有必要,将它们从图像中删除
I have made a wordcloud using python and I want to look at the words in the wordcloud and if necessary, remove them from the image
所以基本上,我有一个文件,其中有一些列表,我想使用这些列表来查看单词是否存在于我所提供的字典中,如果是,则从中形成一个词云。现在看了wordcloud之后我想从图片中删除一些无用的词,你们可以帮我吗?
from wordcloud import WordCloud
import matplotlib.pyplot as plt
import module1
import module2
lst = input('Which list?')
a = module2.diction
c = None
if lst == 'list1':
c=module2.list1
if lst == 'list2':
c=module2.list2
#print(c)
#doing stuff with the dictionary I had
for name, numb in a.items():
for key in numb:
key = key * numb[key]
a[name] = key
#print(sample)
quad = ({key : a[key] for key in a if key in c})
#print(quad)
wc = WordCloud(background_color="white",width=1000,height=1000,colormap="copper", relative_scaling=0.5,
normalize_plurals=False).generate_from_frequencies(quad)
# Plot
plt.figure()
plt.ion()
plt.imshow(wc, interpolation="bilinear")
plt.margins(x=0, y=0)
plt.axis('off')
plt.tight_layout(pad=0)
plt.ioff()
plt.show()
u = input('Enter the words: ')
如果您想从字典中删除某些内容,您可以使用以下语法:
del dictonary[word]
这将从字典中删除单词,因此如果您遇到单词 the
并想删除它,您可以使用
del c['the']
所以基本上,我有一个文件,其中有一些列表,我想使用这些列表来查看单词是否存在于我所提供的字典中,如果是,则从中形成一个词云。现在看了wordcloud之后我想从图片中删除一些无用的词,你们可以帮我吗?
from wordcloud import WordCloud
import matplotlib.pyplot as plt
import module1
import module2
lst = input('Which list?')
a = module2.diction
c = None
if lst == 'list1':
c=module2.list1
if lst == 'list2':
c=module2.list2
#print(c)
#doing stuff with the dictionary I had
for name, numb in a.items():
for key in numb:
key = key * numb[key]
a[name] = key
#print(sample)
quad = ({key : a[key] for key in a if key in c})
#print(quad)
wc = WordCloud(background_color="white",width=1000,height=1000,colormap="copper", relative_scaling=0.5,
normalize_plurals=False).generate_from_frequencies(quad)
# Plot
plt.figure()
plt.ion()
plt.imshow(wc, interpolation="bilinear")
plt.margins(x=0, y=0)
plt.axis('off')
plt.tight_layout(pad=0)
plt.ioff()
plt.show()
u = input('Enter the words: ')
如果您想从字典中删除某些内容,您可以使用以下语法:
del dictonary[word]
这将从字典中删除单词,因此如果您遇到单词 the
并想删除它,您可以使用
del c['the']