Commit 3a644c31 by BellCodeEditor

auto save

parent 6b1fbc15
import wordcloud#导入模块
w = wordcloud.WordCloud(background_color="pink") #设置词云背景颜色
w.generate("Hello Kuruite") #词云内容
w.to_file("myy.png") #生成的词云图片
import wordcloud #导入词云模块
w = wordcloud.WordCloud(background_color="blue") #词云背景颜色
w.generate("hello bellcode") #词云中单词
w.to_file("my.png") #生成图片文件
\ No newline at end of file
my.png

8.41 KB

import wordcloud
\ No newline at end of file
import wordcloud
from PIL import Image
import numpy
img = Image.open("alice.png")
da = numpy.array(img)
img_colors = wordcloud.ImageColorGenerator(da)
# 创建词云对象
w=wordcloud.WordCloud(background_color="white",
font_path='SimHei.ttf',
mask=da,color_func=img_colors)
with open('python二级考试大纲.txt', encoding='utf-8') as f:
text = f.read()
# 传入词云文本内容
w.generate(text)
# 保存为png图片
w.to_file("my_alice.png")
myy.png

7.06 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