赞
踩
词云图进阶版:
这是画布着色+画布轮廓的进阶版本哦~
备注:图片将替换保存,注意先copy一份
- import jieba
- #画图模块
- import matplotlib.pyplot as plt
- #文字云模块
- from wordcloud import WordCloud, ImageColorGenerator, STOPWORDS
- #读取背景图片
- import numpy as np
- from PIL import Image
-
-
- filename = "citu2.txt"
- picture = "a.jpg"
- shape = "a.jpg"
- font_path = "C:/Windows/Fonts/STXINWEI.TTF"
- girl_color = np.array(Image.open(shape))
- image_colors = ImageColorGenerator(girl_color)
-
- # 用 stopwords.add()设置屏蔽显示的词语,可以添加多个
- stopwords = set(STOPWORDS)
- stopwords.add("aaaa")
- stopwords.add("bb")
-
- text = open(filename).read()
-
- wd = WordCloud(
- width=1024,
- height=768, # width,height设置生成的词云图片的大小
- font_path=font_path, # 设置字体为本地的字体,有中文必须要加
- background_color="white", # 设置背景的颜色,需与背景图片的颜色保持一致,否则词云的形状会有问题
- m
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。