From eafe8d738e467e2bef443bf8d1c1eb25a23c0448 Mon Sep 17 00:00:00 2001 From: pg7s85mrc <3224571700@qq.com> Date: Wed, 18 Sep 2024 17:25:32 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E6=88=90=E8=AF=8D=E4=BA=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1111.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 1111.py diff --git a/1111.py b/1111.py new file mode 100644 index 0000000..95f17c6 --- /dev/null +++ b/1111.py @@ -0,0 +1,37 @@ +import jieba +import wordcloud +import imageio +from wordcloud import ImageColorGenerator + +#读取本地图片 +img = imageio.imread('img.png') +#读取保存的弹幕数据 +data = open('3.txt',encoding='utf-8') +text = data.read() +#print(text) +#分割词语 +word = jieba.lcut(text) +print(word) +#转换为字符串 +str = ' '.join(word) +print(str) +# 生成颜色映射 +image_colors = ImageColorGenerator(img) +#绘制词云图 +wc = wordcloud.WordCloud( + width=800, + height=800, + background_color='white', + mask=img, + contour_color='black', + contour_width=1, + stopwords={'哈','了','的','啊','你','是','我','吗','这','他','都','吧','这个','和','也','在','好','有','不','就','哈哈哈','不是','就是','说', + '真的','很','人','看','还','哈哈','哈哈哈哈','还是','没有','没','呢','什么','要','能','给'}, + font_path='msyh.ttc' + + +) +wc.generate(str) +wc.recolor(color_func=image_colors) +wc.to_file("ai词云.png") +