Commit 1c30a202 by BellCodeEditor

save project

parent 644b0b23
Showing with 27 additions and 6 deletions
import jieba
from wordcloud import WordCloud,STOPWORDS
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
wc=WordCloud(mask=np.arry(Image.open("./picture/bell.png"),background_color="white",max_words=2000,height=400,width=800,max_font_size=50,stopwords=" ",
font_path='C:/Windows/Fonts/SimHei.ttf')
wc.generate("C:\Users\Administrator\Desktop\python二级考试大纲.txt")
plt.imshow(wc,interpolation='bilinear')
import jieba
f=open('python二级考试大纲.txt','r',encoding='utf-8')
txt=f.read()
f.close()
words = jieba.lcut(txt)
counts={}
chiyun=[]
for word in words:
if len(word)<2:
continue
else:
counts[word]=counts.get(word,0)+1
items=list(counts.items())
items.sort(key=lambda x: x[1],reverse=True)
for i in range(len(items)):
word,counts=items[i]
chiyun.append(word)
print(chiyun)
maskph=np.array(Image.open('alice.png'))
text_cut='/'.join(chiyun)
wc=WordCloud(mask=maskph,background_color="white",max_words=2000,height=400,width=800,max_font_size=50,stopwords=" ",
font_path='simhei.ttf').generate(text_cut)
plt.imshow(wc)
plt.axis('off')
plt.show()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment