wordcluod词图笔记

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)

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值