红楼梦词云制作(带背景)
生活随笔
收集整理的這篇文章主要介紹了
红楼梦词云制作(带背景)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
初學望批評指正。
紅樓詞云帶背景圖的那種。
原始圖像:
原始圖像 原始的扣下來的林妹妹?最終用ps合成的圖。其實挺唏噓的,一般人認為黛玉是絕對的女主,但是黛玉只出現了900多次,不及賈母3000次、鳳姐的1000次。
這個是人物出場次數統計:
人物出場次數這個是我的另一個帖子,?紅樓夢人物出場統計
最終的成片。摳圖畢竟簡陋。
紅樓詞云(林妹妹版)源代碼如下:?
#GovRptWordCloudv1.py import jieba import wordcloud import imageio mask = imageio.imread("01.jpg") f = open("dreams01.txt", "r", encoding="utf-8") t = f.read() f.close() words = jieba.lcut(t) counts = {} for word in words:if len(word) == 1:continueelif word == "老太太" or word == "太太" or word == "老祖宗" or word == "史太君":rword = "賈母"elif word == "老爺":rword = "賈政"elif word == "寶二爺":rword = "寶玉"elif word == "王熙鳳" or word == "熙鳳" or word == "鳳辣子":rword = "鳳姐"elif word == "林黛玉" or word == "瀟湘妃子" or word == "林丫頭" or word == "林妹妹":rword = "黛玉"elif word == "寶姑娘" or word == "寶丫頭" or word == "蘅蕪君" or word == "寶姐姐":rword = "寶釵"else:rword = wordcounts[rword] = counts.get(rword, 0) + 1items = list(counts.items()) txt = " ".join(words) w = wordcloud.WordCloud( font_path = "msyh.ttc", mask = mask, \width = 1000, height = 700, background_color = "white", \) w.generate(txt) w.to_file("grwordcloud4.png")?
總結
以上是生活随笔為你收集整理的红楼梦词云制作(带背景)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Ceph 集群基础
- 下一篇: 南京都昌公司乔迁之志