欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python wordcloud matplotlib(绘图)

程序员文章站 2022-03-21 14:25:12
...
##############matplotlib################
import maplotlib.pyplot as plt
import numpy as np 
# 绘制曲线
x = linspace(0, 10, 100)
ps = plot(x, sin(x), x, cos(x))
# 加文字
t1 = text(1, -0.5, "hello")
# 文字坐标改变
t1.set_position([7, -0.5])
# 文字移除
t1.remove()

# 曲线移除
Artist.remove()

# y轴范围
ylim(-1.1, 1.1)
##############wordcloud################import jieba
import jieba.analyse
from wordcloud import WordCloud
from wordcloud import ImageColorGenerator
import matplotlib.pyplot as plt
from scipy.misc import imread

# 输入数据
tfidf = []
inputs = open('C:\\Users\\NAU\\Desktop\\sample.txt', 'r', encoding='utf8')
outputs = open('C:\\Users\\NAU\\Desktop\\neg_tfidf.txt', 'w', encoding='utf8')
nagetive_top_words = inputs.read()
inputs.close()
# 词频tfidf权重计算
tags = jieba.analyse.extract_tags(nagetive_top_words, topK=100, withWeight=False)
text = " ".join(tags)
# 图片背景
bj_pic = imread('C:\\Users\\NAU\\Desktop\\ss.png')
# wordcloud相似词
wc = WordCloud(font_path="C:\\Windows\\Fonts\\STFANGSO.ttf", background_color="white", mask=bj_pic, max_words=100,
                width=1600, height=800)
wc.generate(text)
image_colors = ImageColorGenerator(bj_pic)
# 显示图片
plt.figure("lending comments")  # 指定所绘图名称  
plt.imshow(wc)  # 以图片的形式显示词云  
plt.axis("off")  # 关闭图像坐标系  
plt.show()