import matplotlib.pyplot as plt
import jieba
import string
from wordcloud import WordCloud
lines=open('getting').readlines()
s=''
i=2
while i<len(lines):
s+=lines[i]
i+=4
jieba.load_userdict('userdict')
seg_list = jieba.lcut(s, cut_all=False)
final=''
for i in seg_list:
final+=(i+' ')
stopword_da=[]
l=open('stopword').read()
stopword_da=l.split()
print(stopword_da[:10])
wc1 = WordCloud(
background_color="white",
font_path='SourceHanSansCN-Normal.ttf',
stopwords=stopword_da,
width=1000,
height=860,
scale=20,
max_words = 100,
margin=2)
wc2 = wc1.generate(final)
plt.imshow(wc2)
plt.axis("off")
plt.savefig('wc.jpg', dpi=600, bbox_inches='tight
Python统计一门课里的关键词并生成词图
最新推荐文章于 2024-11-05 15:28:12 发布