From dae736fb40d515500a43fd533fed9b8cb421b572 Mon Sep 17 00:00:00 2001 From: pfigcozwn <2731023261@qq.com> Date: Tue, 2 May 2023 14:05:54 +0800 Subject: [PATCH] ADD file via upload --- 词云图.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 词云图.py diff --git a/词云图.py b/词云图.py new file mode 100644 index 0000000..6ea1413 --- /dev/null +++ b/词云图.py @@ -0,0 +1,40 @@ + +# coding: utf-8 + +# In[1]: + + +from collections import Counter +import numpy as np +from PIL import Image +from wordcloud import WordCloud, STOPWORDS +import matplotlib.pyplot as plt +import pandas as pd +# 读取数据 转化为字符串形式 +data = pd.read_csv('./temp/task3.csv', encoding='gbk') +text = ''.join(data["柜组名称"]) +#换图片 +logo_mask = np.array(Image.open('02.png')) +# 配置词云图属性 +wc = WordCloud(background_color='white', + max_words=2000, + stopwords=STOPWORDS, + font_path='./data/simhei.ttf', + mask=logo_mask,#遮罩 + contour_width=3, + contour_color='gray', + width=800, + height=400, + repeat=True, + random_state=42) + +words = wc.generate(text) + +# 显示词云图 +plt.imshow(words, interpolation='bilinear') +plt.axis('off') +plt.show() + +# 保存词云图 +wc.to_file('wordcloud.jpg') +