#coding=utf-8
#encoding=utf8
import jieba
from jieba.analyse import extract_tags
from scipy.misc import imread
from wordcloud import WordCloud, ImageColorGenerator
import matplotlib.pyplot as plt
from PIL import Image
import numpy as np
path_text = r'C:\Users\Administrator\Desktop\classname.txt'
f=open(path_text,mode='r',encoding='utf-8',errors='ignore').read()
# with open (path_text) as f:
cut_text=" ".join(jieba.cut(f))
image=Image.open("E:\python爬虫\photo.png")
graph=np.array(image)
wordcloud=WordCloud(font_path="C:\Windows\Fonts\simhei.ttf",min_font_size=14,stopwords=["excel","Excel","Excel2013","Excel2016","视频教程","应用","教程","实战","技巧","课程","Oeasy","职场","高级","基础","玩转","Office","入门","办公"],background_color="white",mask=graph).generate(cut_text)
image_color=ImageColorGenerator(graph)
wordcloud.recolor(color_func=image_color)
wordcloud.to_file(r'E:\python爬虫\wordcloud.png')
plt.imshow(wordcloud)
plt.axis("off")
plt.show()