matplotlib词云和饼状图的标注问题

为啥词云的左上角会出现饼状图的标注,怎么去掉词云这部分的标注,还有饼状图柱状图和词云函数的调用顺序也会影响最后绘制出来的图片,这是为什么???

import pymongo
import snownlp as sn
import matplotlib.pyplot as plt
import numpy as np
import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import jieba
from os import path
from PIL import Image
from wordcloud import WordCloud

bg = np.array(Image.open("./data/233.jpg"))
d = path.dirname(__file__)

stopwords_path = './data/stop_word.txt'

text_path = "test.txt"
text = open(path.join(d, text_path), encoding='utf-8').read()

class filedialogdemo(QWidget):
def init(self, parent=None):
super(filedialogdemo, self).__init__(parent)
layout = QHBoxLayout()
self.lable1 = QLabel()
self.lable1.setPixmap(QPixmap("./data/bar.jpg"))
layout.addWidget(self.lable1)
self.lable2 = QLabel()
self.lable2.setPixmap(QPixmap("./data/pie.jpg"))
layout.addWidget(self.lable2)
self.lable3 = QLabel()
self.lable3.setPixmap(QPixmap("./data/WordCloud.png"))
layout.addWidget(self.lable3)
self.setLayout(layout)
self.setWindowTitle("Result")

def sentiment(text):
if text == '':
return 0.5
else:
s = sn.SnowNLP(text)
return s.sentiments

def Paint_Bar(num1, num2, num3, num4):
plt.rcParams['font.sans-serif'] = ['SimHei'] #显示中文
plt.bar(0.125, num1,width=0.1, label='really bad')
plt.bar(0.375, num2,width=0.1, label='bad')
plt.bar(0.625, num3,width=0.1, label='good')
plt.bar(0.875, num4,width=0.1, label='really good')
plt.text(0.125, num1 + 0.5, '%d' % num1, ha='center', va='bottom')
plt.text(0.375, num2 + 0.5, '%d' % num2, ha='center', va='bottom')
plt.text(0.625, num3 + 0.5, '%d' % num3, ha='center', va='bottom')
plt.text(0.875, num4 + 0.5, '%d' % num4, ha='center', va='bottom')
plt.xlabel(u'x轴')
plt.ylabel(u'y轴')
ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
plt.xlim(0, 1)
plt.xticks([0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1])
plt.title(u'柱形图')
plt.legend()
plt.savefig('./data/bar.jpg')

def Paint_Scatter(list):
plt.rcParams['font.sans-serif'] = ['SimHei'] # 显示中文
plt.title(u'散点图')
list_len = len(list)
for list_num in range(list_len):
plt.scatter(list[list_num], list[list_num])

def Paint_Pie(num1, num2, num3, num4):
list = []
list.append(num1)
list.append(num2)
list.append(num3)
list.append(num4)
s = np.max(list)
if s == num1:
k = 0
elif s == num2:
k = 1
elif s == num3:
k = 2
else:
k = 3
explode = [0,0,0,0]
explode[k] = 0.1
labels = 'really bad', 'bad', 'good', 'really good'
plt.axes(aspect=1) #椭圆变标准圆
plt.pie(x=list, explode=explode, labels=labels, autopct='%3.1f %%',
shadow=True, labeldistance=1.1, startangle=90, pctdistance=0.6)
plt.axis('equal')
plt.savefig('./data/pie.jpg')

def JiebaClearText(text):
MywordList = []
seg_list = jieba.cut(text, cut_all=False)
listStr = '/'.join(seg_list)
f_stop = open(stopwords_path, encoding='utf-8')
try:
f_stop_text = f_stop.read()
finally:
f_stop.close()
f_stop_seg_list = f_stop_text.split("\n")
for myword in listStr.split('/'):
if not(myword.split()) in f_stop_seg_list and len(myword.strip()) > 1:
MywordList.append(myword)
return ' '.join(MywordList)

def Paint_cloud():
text1 = JiebaClearText(text)

wc = WordCloud(background_color="white",
               max_words=150,
               mask=bg,  # 设置图片的背景
               max_font_size=60,
               random_state=42,
               font_path='C:/Windows/Fonts/simkai.ttf'  # 中文处理,用系统自带的字体
               ).generate(text1)
plt.imshow(wc, interpolation="bilinear")
plt.axis("off")
plt.savefig('./data/WordCloud.png')

def run():
num1 = 0
num2 = 0
num3 = 0
num4 = 0
list0 = []
mongo_uri = 'mongodb://localhost:27017/'
client = pymongo.MongoClient(mongo_uri)
db = client.weibo
collection = db.weibo
data = collection.find()
data = list(data)
list_len = int(len(data))
f = open('test.txt', 'w', encoding='utf-8')
for num in range(list_len):
dict = data[num]
text = dict['content']
f.write(text)
if text != ':' and text != 0:
text_num = sentiment(text)
list0.append(text_num)
if text_num < 0.25:
num1 += 1
elif text_num < 0.5:
num2 += 1
elif text_num <0.75:
num3 += 1
else:
num4 += 1
f.close()

Paint_Bar(num1, num2, num3, num4)   #柱形图
Paint_Pie(num1, num2, num3, num4)   #饼状图
Paint_cloud()                       #词云

app = QApplication(sys.argv)
ex = filedialogdemo()
ex.show()
sys.exit(app.exec_())

if name == '__main__':
run()
图片说明

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问