Commit e8bcfe28 by BellCodeEditor

auto save

parent 6b1fbc15
Showing with 27 additions and 2 deletions
1.jpg

29.3 KB

gao.jpg

19.8 KB

import wordcloud
\ No newline at end of file
import wordcloud
from PIL import Image
import numpy as np
import jieba
with open('python二级考试大纲.txt', 'r', encoding='utf-8')as file:
text = file.read()
text_list = jieba.lcut(text)
text = "".join(text_list)
# 读取图片
img = Image.open('1.jpg')
# 将图片RGB像素值转成多维数组
data = np.array(img)
img_colors = wordcloud.ImageColorGenerator(data)
#小括号元组 ,中括号 列表 ,大括号 集合或字典
stopwords = {'的','python','和','基本','程序','必选'}
# 创建词云对象
w = wordcloud.WordCloud(background_color='white',
font_path='SimHei.ttf',
mask=data,
color_func=img_colors,
stopwords=stopwords,
max_font_size=30)
# 传入词云内容
w.generate(text)
# 保存图片
w.to_file('mycloud.png')
mycloud.png

70.1 KB

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