from PIL import Image
import wordcloud
import jieba
import numpy as np
import pandas as pd
from wordcloud import WordCloud
def get_word_j(texts):#
cut = jieba.lcut(texts)
string = ' '.join(cut)
print('get_word OK')
return string
def get_word_q(texts):#
cut = jieba.lcut(texts,cut_all=True)
string = ' '.join(cut)
print('get_word OK')
return string
def get_word_s(texts):#
cut = jieba.lcut_for_search(texts)
string = ' '.join(cut)
print('get_word OK')
return string
def make_wc(string,img_path,cwimg_path):
img_array = np.array(Image.open(img_path))
wc = WordCloud(
background_color = 'white',
#width = 1000,
#height = 800,
collocations = False,
mask = img_array, #云样子,图片的numpy数组类型
font_path = "msyh.ttc" #字体路径默认None
#stop_words = {"高分","回复"}
#min_font_size = #最大字号
#max_font_size = #最小字号
#font_step = #字号步进,默认1
#max_words = #最多文字数,默认200
)
wc.generate(string)
wc.to_file(cwimg_path)
print('make_wc OK')
with open("C:\\Users\\西木康\\Desktop\\爬虫1\\120.txt","r",encoding='utf-8')as f:
text = f.read()
string = get_word_j(text)
string = string.replace('回复','')
img_path = "C:\\Users\\西木康\\Desktop\\爬虫1\\102.png"
cwimg_path = "C:\\Users\\西木康\\Desktop\\爬虫1\\151.png"
make_wc(string,img_path,cwimg_path)
wordcluod词图笔记
最新推荐文章于 2023-12-11 01:07:35 发布