词云图进阶版,带轮廓:

import jieba
#画图模块
import matplotlib.pyplot as plt
#文字云模块
from wordcloud import WordCloud
#读取背景图片
from scipy.misc import imread

#文件名
word_file='citu3.txt'
#读取文件内容
word_content=open(word_file,'r').read().replace('\n','')
#设置背景图片
img_file='a.jpg'
#读取背景图片
mask_img=imread(img_file)
#进行分词
word_cut=jieba.cut(word_content)
#把分词用空格连起来
word_cut_join=" ".join(word_cut)
#生成词云
wc=WordCloud(
              font_path='C:/Windows/Fonts/STXINWEI.TTF',#设置字体
             max_words=100,#词云显示的最大词数
             mask=mask_img,#设置背景图片
             background_color='white'#背景颜色
             ).generate(word_cut_join)

plt.imshow(wc)
#去掉坐标轴
plt.axis('off')
#将图片保存到本地
plt.savefig('d.jpg')
plt.show()

【python】词云图,进阶版

相关文章:

  • 2022-12-23
  • 2021-10-09
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2021-12-30
  • 2022-01-02
  • 2022-12-23
猜你喜欢
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2021-06-27
  • 2021-08-04
相关资源
相似解决方案