【Python~分享】制作大数据词云展示

import jieba
import imageio
from wordcloud import WordCloud,ImageColorGenerator
from matplotlib import pyplot as plt
#字体库
font=r"D:\Python_things\FontFamily\Muya.ttf"
#待解析文本库
text=""
text_path=r"D:\Python_things\require.txt"
with open(text_path,"r",encoding="utf-8") as f:
    text=f.read()
#
#背景图片
img_path=r"D:\Python_things\bgim.png"
bg_image=imageio.imread(img_path)
#
# 提取标点符号库
words_path=r"D:\Python_things\StopWords\stopwords.txt"
stopWords=[]
with open(words_path,"r",encoding="utf-8") as f:
    stopWords=f.read().split("\n")
#
show_words=[]#定义显示数组
waiting_str=jieba.cut(text)#待显示的字符串,加入/
for res in waiting_str:
    if (res.strip() not in stopWords)and res.strip()!=""and len(res.strip())>1:
        show_words.append(res)
wc = WordCloud(
    background_color='white',
    width=1000,
    height=800,
    max_words=3000,
    mask=bg_image,
    font_path=font,
    random_state=200,
    min_font_size=15,
    max_font_size=50
)
wc.generate(" ".join(show_words))
image_colors = ImageColorGenerator(bg_image)
plt.imshow(wc.recolor(color_func=image_colors))
plt.imshow(wc)
plt.axis("off")
plt.show()
wc.to_file("D:\Python_things\img.png")

运行结果:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值