環境:python3.6
第三方庫:matplotlib、wordcloud、pil
**如下:
執行展示效果:
----------------------------分割線-------------------------------------------
以上使用於英文文字,中文文字流程如下
第三方庫:matplotlib、wordcloud、pil、jieba、numpy
from wordcloud import wordcloud
import pil.image as image
import numpy as np
import jieba
# 分詞
def trans_cn(text):
# 接收分詞的字串
word_list = jieba.cut(text)
# 分詞後在單獨個體之間加上空格
result = " ".join(word_list)
return result
with open("love.txt",encoding="utf-8") as fp:
text = fp.read()
# print(text)
# 將讀取的中文文件進行分詞
# 新增遮罩層
mask=mask,
# 生成中文字的字型,必須要加,不然看不到中文
font_path="c:\windows\fonts\stxingka.ttf"
).generate(text)
image_produce = wordcloud.to_image()
image_produce.show()
執行效果圖如下:
python 生成簡單的詞云
frommatplotlibimportpyplot fromwordcloudimportwordcloud,imagecolorgenerator importjieba,pymysql fromscipy.miscimportimread 這是乙個處理影象的函式 conn pymysql.co...
Python 生成詞云
import matplotlib.pyplot as plt from wordcloud import wordcloud import jieba text from file with apath open python.txt encoding utf 8 read wordlist af...
python 生成詞云
coding utf 8 from wordcloud import wordcloud import matplotlib.pyplot as plt import jieba from pil import image import numpy as np 生成詞云 defcreate word...