python-3.x - 我使用 python 制作了一个 wordcloud,我想查看 wordcloud 中的单词,如有必要,将它们从图像中删除
问题描述
所以基本上,我有一个文件,其中有一些列表,我想用这些列表来查看这些单词是否存在于我给定的字典中,如果是,则从中形成一个 wordcloud。现在看了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']
推荐阅读
- java - 以下java函数没有将数据插入数据库,
- javascript - 来自 javascript 的 asp.net MVC 调用控制器
- asp.net-web-api - 如何增加 .net core 中的请求限制?
- android - 如何在使用 React Native 导航时将推送通知集成到 React Native 中
- json - 火花,蜂巢;系统设计问题每天处理 2TB
- php - onerror 显示无 - php ($.row['img'])
- mips - MIPS 写数字列表的练习
- php - 如何过滤数组中的值
- math - 数学数字系统
- php - 如何处理 mysql 和 laravel 中的数百万条记录