第一、理论准备
1 读取图片背景
bimg = imread(imgFilePath)
2 获取图片颜色
bimgColors=ImageColorGenerator(bimg)
3 重制词云的颜色
wordcloud.recolor(color_func=bimgColors)
第二、案例代码实践
import codecs;
content=[]
f=codecs.open("D:databasepython2.5红楼梦.txt",'r','utf-8')
content=f.read()
f.close()
import jieba;
import pandas;
segments=[]
jieba.load_userdict(
'D:databasepython2.5红楼梦词库.txt')
segs =jieba.cut(content)
for seg in segs:
if len(seg) >1 :
segments.append(seg);
segmentDF=pandas.DataFrame({'segment':segments})
stopwords= pandas.read_csv(
'D:databasepython2.5StopwordsCN.txt',
encoding='utf-8',
index_col=False,
quoting=3,
sep="t")
segmentDF=segmentDF[
~segmentDF.segment.