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