28 lines
794 B
Python
28 lines
794 B
Python
from wordcloud import WordCloud
|
|
# python的可视化库,也是二级考试推荐的可视化库
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
str=['齐天大圣','大圣','大圣','八戒','嫦娥']
|
|
#数组里面添加内容
|
|
str.append('玉兔')
|
|
str.append('女儿国')
|
|
str.append('牛魔王')
|
|
str.append('大圣')
|
|
str.append('土地公公')
|
|
str.append('小神仙')
|
|
str.append('八戒')
|
|
|
|
print(str)
|
|
#join 函数 用斜杆拼接词组mask =maskph,
|
|
#这里一定要join拼接一下 转成字符串
|
|
text_cut = '/'.join(str)
|
|
|
|
#看一下连接后的样子
|
|
#关键点 text_cut 是词云要处理的内容
|
|
print(text_cut)
|
|
wordcloud = WordCloud( background_color='white',font_path = 'msyh.ttc', width=1000, height=860, margin=2).generate(text_cut)
|
|
# 显示图片
|
|
plt.imshow(wordcloud)
|
|
plt.axis('off')
|
|
plt.show() |