Python 词云
#matplotlib #wordcloud #NLP
在进行词云展示之前需要对文本数据进行分词处理,处理为一定格式的词的汇总的形式,常用到的工具有jieba,nltk等。
from wordcloud import WordCloud
from wordcloud import *
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
color_mask = mpimg.imread("./th.jpg") # 读取背景图片
image_colors = ImageColorGenerator(color_mask)
cloud = WordCloud(
#设置字体,不指定就会出现乱码
font_path="simkai.ttf",
#font_path=path.join(d,'simsun.ttc'),
#设置背景色
background_color='white',
#词云形状
mask=color_mask,
#允许最大词汇
max_words=200,
#最大号字体
max_font_size=2000
)
word_cloud = cloud.generate(str(wds)) # 产生词云
# 显示词云图片
plt.imshow(word_cloud)
word_cloud.to_file("pjl_cloud4.jpg") #保存图片
#Matplotlib
plt.title('name') #为图像添加标题
plt.xlabel(‘name’) #添加x轴标签
plt.ylabel