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")

运行结果:
【Python~分享】制作大数据词云展示

相关文章:

  • 2021-08-20
  • 2022-02-02
  • 2022-12-23
  • 2022-01-08
  • 2021-11-28
  • 2021-07-09
  • 2021-12-27
  • 2021-08-13
猜你喜欢
  • 2021-04-04
  • 2021-11-20
  • 2021-11-11
  • 2021-11-17
  • 2021-07-13
  • 2021-12-29
  • 2021-10-07
相关资源
相似解决方案