from wordcloud import WordCloud +matplotlib.pyplot画词云图!

from wordcloud import WordCloud +matplotlib.pyplot画词云图!

from pyecharts.charts import WordCloud词云可视化我的另一篇词云图文https://blog.csdn.net/qq_45058254/article/details/103940713

# -*- coding: utf-8 -*-
# @Project filename:PythonDemo  WordCloud-像我这样的人.py
#@IDE   :IntelliJ IDEA
#@Author :ganxiang
#@Date   :2020/02/22 0022 16:04

import jieba
from wordcloud import WordCloud
import matplotlib.pyplot as plt

with open('./Read/像我这样的人.txt','r',encoding='utf-8')as f:
    # cut_txt =" ".join(f.read())#空格划分
    cut_txt =f.read()
    print(cut_txt)
    photo =plt.imread('./Read/10.jpg')#形成词云图的图片形状
    wordcloud =WordCloud(
            font_path="simhei.ttf",#设置输出词云的字体
            max_font_size=100,#设置字体的大小,默认200
            background_color='white',
            width=2300,height=1900,
            scale=3,#设置图的词密度
            random_state=50,## random.Random用来生成随机颜色
            mask=photo#设置图片形状,
            ).generate(cut_txt)#generate()根据文本生成词云
    plt.imshow(wordcloud,interpolation="nearest")
    plt.axis("off")#关闭x,y轴刻度
    plt.savefig('./Save/毛不易-像我这样的人1.jpg')
    plt.show()
#
# plt.imshow()函数负责对图像进行处理,并显示其格式,但是不能显示。
# plt.ishow()其后跟着plt.show()才能显示出来。

#interplotation设置了边界的模糊度,或者是图片的模糊度的值可以为:‘none’,‘nearest’,‘bilinear’,‘bicubic’,
# ‘spline16’, ‘spline36’, ‘hanning’, ‘hamming’,‘hermite’,‘kaiser’,
# ‘quadric’,‘catrom’,‘gaussian’,‘bessel’,‘mitchell’, ‘sinc’,‘lanczos’

效果展示
在这里插入图片描述
在这里插入图片描述
像我这样的人.txt
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值