From 70c5f1e99164492cb44224286b51e9b35c821289 Mon Sep 17 00:00:00 2001 From: palc3e6gq <1622356900@qq.com> Date: Mon, 16 Sep 2024 22:27:11 +0800 Subject: [PATCH] ADD file via upload --- 生成词云.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 生成词云.py diff --git a/生成词云.py b/生成词云.py new file mode 100644 index 0000000..a4de0af --- /dev/null +++ b/生成词云.py @@ -0,0 +1,23 @@ +import jieba +import wordcloud +import imageio +#1.读取弹幕数据 +f =open("总弹幕.txt",encoding='utf-8') +text =f.read() +#2.分词 +text_list=jieba.lcut(text) +text_str=' '.join(text_list) +#3.词云图 +f2=open("中文常见停用词.text",encoding='utf-8') +text2=f2.read().splitlines()#读取弹幕 +img= imageio.v2.imread('地球.png')#导入词云形状的图片 +wc=wordcloud.WordCloud(#设置词云格式 + width=1160,#宽 + height=800,#高 + background_color='white',#背景颜色 + mask=img,#云图样式 + stopwords=text2,#禁用词 + font_path='msyh.ttc'#字体 +) +wc.generate(text_str) +wc.to_file('词云图.png') \ No newline at end of file