Commit 323ea1ac by BellCodeEditor

auto save

parent ff70ad90
111.jpg

514 KB

import wordcloud
from PIL import Image
import numpy
import jieba
with open('python二级考试大纲.txt', encoding='utf-8') as f:
with open('诡秘.txt', encoding='utf-8') as f:
text = f.read()
list1=jieba.lcut(text)
text1="".join(list1)
img = Image.open('alice.png')
data=numpy.array(img)
img_colors = wordcloud.ImageColorGenerator(data)
# 创建词云对象
w=wordcloud.WordCloud(background_color="white",
font_path='STXINGKA.TTF')
w=wordcloud.WordCloud(background_color="white",width=2080,height=2080,scale=5,
font_path='STXINGKA.TTF',mask=data,color_func=img_colors,
max_font_size=60)
# 传入词云文本内容
w.generate(text)
w.generate(text1)
# 保存为png图片
w.to_file("mycloud.png")
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
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