parent
b0f36dd554
commit
dae736fb40
@ -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')
|
||||
|
Loading…
Reference in new issue