python云图

#安装相关插件
# python3 -m pip install jieba wordcloud matplotlib
import matplotlib.pyplot as plt
import jieba
from wordcloud import WordCloud

#1.读出歌词
text = open('yun.txt').read()
#2.把歌词剪开
cut_text = jieba.cut(text)
# print(type(cut_text))
# print(next(cut_text))
# print(next(cut_text))
#3.以空格拼接起来
result = " ".join(cut_text)
# print(result)
# 4.生成词云
wc = WordCloud(
    font_path='simhei.ttf',     #字体路劲
    background_color='white',   #背景颜色
    width=1000,
    height=600,
    max_font_size=50,            #字体大小
    min_font_size=10,
    mask=plt.imread('yun.png'),  #背景图片
    max_words=1000
)
wc.generate(result)
wc.to_file('yuntu.png')    #图片保存

#5.显示图片
plt.figure('云图')   #图片显示的名字
plt.imshow(wc)
plt.axis('off')        #关闭坐标
plt.show()

 

你可能感兴趣的:(python,python,云图,WordCloud,jieba,PLT)