Python快速簡(jiǎn)單生成矩形詞云
效果
實(shí)現(xiàn)
打開(kāi)IDLE新建文件rectangle.py
import os from os import path from wordcloud import WordCloud from matplotlib import pyplot as plt # 獲取當(dāng)前文件路徑 d = path.dirname(__file__) if "__file__" in locals() else os.getcwd() # 獲取文本text text = open(path.join(d,'aobama.txt')).read() # 生成詞云 wc = WordCloud(scale=2,max_font_size = 100) wc.generate_from_text(text) # 顯示圖像 plt.imshow(wc,interpolation='bilinear') plt.axis('off') plt.tight_layout() #存儲(chǔ)圖像 wc.to_file('aobama.png') # or # plt.savefig('1900_basic.png',dpi=200) plt.show()
在同目錄下新建aobama.txt
這里面放你要生成的詞云的文字
運(yùn)行
保存代碼,并按F5運(yùn)行代碼。
初次運(yùn)行時(shí),會(huì)提示no module ***
根據(jù)對(duì)應(yīng)缺失的庫(kù),打開(kāi)cmd,執(zhí)行pip install **
**為提示的缺失的庫(kù)名。
到此這篇關(guān)于Python快速簡(jiǎn)單生成矩形詞云的文章就介紹到這了,更多相關(guān)Python 矩形詞云內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章

關(guān)于TensorBoard可視化不顯示數(shù)據(jù)問(wèn)題No scalar data was&nbs

python新式類和經(jīng)典類的區(qū)別實(shí)例分析

Python實(shí)現(xiàn)基于Excel數(shù)據(jù)繪制棋盤圖

python GUI庫(kù)圖形界面開(kāi)發(fā)之PyQt5窗口布局控件QStackedWidget詳細(xì)使用方法

中秋送禮分配不均這款python刮刮卡完美解決問(wèn)題