日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 做词云 -jupyter跟随王树义教程学习

發布時間:2025/3/15 python 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 做词云 -jupyter跟随王树义教程学习 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#python 做詞云 -jupyter跟隨王樹義教程學習
參考連接
https://www.jianshu.com/p/e4b24a734ccc
https://www.jianshu.com/p/af6201d2f0c6

安裝 wordcloud

pip install wordcloud

#進入包含txt文件的Jupyter

代碼

記得庫都要安裝

from imageio import imread import matplotlib.pyplot as plt import os from wordcloud import WordCloud, ImageColorGenerator filename = "yes-minister.txt" f = open(filename,encoding='utf-8') #原文檔需要轉換格式 mytext=f.read() from wordcloud import WordCloud wordcloud = WordCloud().generate(mytext) import matplotlib.pyplot as plt plt.imshow(wordcloud,interpolation='bilinear') plt.axis('off')#按照步驟得到的圖

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-idmOra1O-1628130214481)(D:/5bct/output_7_1.png)]

import matplotlib.image as mpimg import numpy as np from PIL import Image#這些代碼參考-http://amueller.github.io/word_cloud/auto_examples/wordcloud_cn.html kust_coloring = np.array(Image.open("kust.jpg"))#自己隨便搞張圖 wc = WordCloud( background_color="white", max_words=2000, mask=kust_coloring) atext=open( "yes-minister.txt",encoding='utf-8').read() image_colors = ImageColorGenerator(kust_coloring) wc.generate(atext)#一開始會說'str'啥的,直接重啟內核 # show fig, axes = plt.subplots(1, 3) axes[0].imshow(wc, interpolation="bilinear") # recolor wordcloud and show # we could also give color_func=image_colors directly in the constructor axes[1].imshow(wc.recolor(color_func=image_colors), interpolation="bilinear") axes[2].imshow(kust_coloring, cmap=plt.cm.gray, interpolation="bilinear") for ax in axes:ax.set_axis_off() plt.show()

?
[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-QGFCSfGm-1628130214484)(D:/5bct/output_16_0.png)]

:
ax.set_axis_off()
plt.show()

? [外鏈圖片轉存中...(img-QGFCSfGm-1628130214484)]

總結

以上是生活随笔為你收集整理的python 做词云 -jupyter跟随王树义教程学习的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。