From fb66ab9b5fb3ae973f6f5c6aa073d9b6e5402a63 Mon Sep 17 00:00:00 2001 From: BellCodeEditor <bellcode_dev@bell.ai> Date: Fri, 30 Jul 2021 17:21:45 +0800 Subject: [PATCH] auto save --- level3-lesson21-diy3.py | 25 +++++++++++++++++++++++++ md.png | Bin 72376 -> 0 bytes my_cloud.py | 6 ------ mycloud.png | Bin 0 -> 569 bytes 4 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 level3-lesson21-diy3.py delete mode 100644 my_cloud.py create mode 100644 mycloud.png diff --git a/level3-lesson21-diy3.py b/level3-lesson21-diy3.py new file mode 100644 index 0000000..809e3b0 --- /dev/null +++ b/level3-lesson21-diy3.py @@ -0,0 +1,25 @@ +import wordcloud +from PIL import Image +import numpy +import jieba + +# 读取文本 +with open('python二级考试大纲.txt', encoding='utf-8') as f: + text = f.read() +txt_list = jieba.lcut(text) +text = " ".join(txt_list) +# 读取图片 +img = Image.open("md.png") +# 将图片RGB像素值转换成多维数组 +data = numpy.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=60) +# 传入词云文本内容 +w.generate(text) +# 保存为png图片 +w.to_file("mycloud.png") diff --git a/md.png b/md.png index a5ba2d1..e866dec 100644 Binary files a/md.png and b/md.png differ diff --git a/my_cloud.py b/my_cloud.py deleted file mode 100644 index 188a62a..0000000 --- a/my_cloud.py +++ /dev/null @@ -1,6 +0,0 @@ -import wordcloud -with open(r'C:\Users\bellcode\Documents\level3-lesson21-diy1\python二级考试大纲.txt',encoding="utf-8") as f: - text=f.read() -w=wordcloud.WordCloud(background_color='white',font_path='SimHei.ttf') -w.generate(text) -w.to_file('md.png') \ No newline at end of file diff --git a/mycloud.png b/mycloud.png new file mode 100644 index 0000000..4102920 Binary files /dev/null and b/mycloud.png differ -- libgit2 0.25.0