Lyric Cloud of Ice and Fire

Picture background:

 

Source code:

import jieba
import wordcloud
import imageio
m = imageio.imread ("Song of Ice and Fire.jpg")
f = open ("Song of Ice and
Fire.txt ", "r") t = f.read ()
txt = jieba .lcut (t)
f.close ()
wordlist = "". join (txt)
w = wordcloud.WordCloud (font_step = 2, background_color = "red", \
                      font_path = "msyh.ttc", mask = m, width = 800, \
                      height = 600, stopwords = {"next page", "directory page", \
                                            "previous page"}, max_words = 200)
w.generate (wordlist)
w.to_file ("Song of Ice and Fire. png ")

Effect picture:

 

Thanks to Ye Xu and Lai Yilin for their help, I only got a little bit after reading the blog posts of other students in the class.

The difficulties encountered are mainly in the installation and debugging, and the final debugging really makes people mentality.

 

Guess you like

Origin www.cnblogs.com/zjy614654231/p/12684645.html