怎么通过做网站来赚钱,坪山网站建设方案,做网站花多钱,百度关键词优化师报错场景原因
在界面设计时#xff0c;想实时更新用matplotlib绘制的图像,即会一次次的调用plot函数#xff0c;这样就会重复地向groupbox里面添加布局#xff0c;但是一个容器只能有一个布局#xff0c;因此会报错 def __init__(self):super(weibo_search_logic, se…报错场景原因
在界面设计时想实时更新用matplotlib绘制的图像,即会一次次的调用plot函数这样就会重复地向groupbox里面添加布局但是一个容器只能有一个布局因此会报错 def __init__(self):super(weibo_search_logic, self).__init__()self.setupUi(self)self.setWindowIcon(QIcon(rresources/icon.ico))self.run() def plot(self,li): result_dict li[-1]negative,medium,positive result_dict[负],result_dict[中],result_dict[正]self.gridlayout2 QGridLayout(self.groupBox) # 继承容器groupBoxself.F2 MyFigure(width4, height5, dpi100)# 将横、纵坐标轴标准化处理确保饼图是一个正圆否则为椭圆self.F2.axes self.F2.fig.add_subplot(111)# self.F2.axes(aspectequal)# 绘制饼图self.F2.axes.pie(x[negative,medium,positive], # 绘图数据labels[负向, 中性, 正向], # 添加教育水平标签autopct%.2f%%, # 设置百分比的格式这里保留一位小数pctdistance0.8, # 设置百分比标签与圆心的距离labeldistance1.55, # 设置水平标签与圆心的距离startangle180, # 设置饼图的初始角度radius1.3, # 设置饼图的半径counterclockFalse, # 是否逆时针这里设置为顺时针方向wedgeprops{linewidth: 1.5, edgecolor: red}, # 设置饼图内外边界的属性值# textprops{fontsize: 10, color: black}, #设置文本标签的属性值)# 添加图标题self.F2.axes.set_title(情感倾向占比图)self.F2.fig.legend()# self.F2.fig.tight_layout()self.gridlayout2.addWidget(self.F2, 0, 0)print(positive)解决方案
将布局代码放在__init__函数中运行一次如果要实时更新的话需要调用self.gridlayout2.update()来更新容器布局中的图像 def __init__(self):super(weibo_search_logic, self).__init__()self.setupUi(self)self.setWindowIcon(QIcon(rresources/icon.ico))self.gridlayout2 QGridLayout(self.groupBox) # 继承容器groupBoxself.run()
def plot(self,li): result_dict li[-1]negative,medium,positive result_dict[负],result_dict[中],result_dict[正]self.F2 MyFigure(width4, height5, dpi100)# 将横、纵坐标轴标准化处理确保饼图是一个正圆否则为椭圆self.F2.axes self.F2.fig.add_subplot(111)# self.F2.axes(aspectequal)# 绘制饼图self.F2.axes.pie(x[negative,medium,positive], # 绘图数据labels[负向, 中性, 正向], # 添加教育水平标签autopct%.2f%%, # 设置百分比的格式这里保留一位小数pctdistance0.8, # 设置百分比标签与圆心的距离labeldistance1.55, # 设置水平标签与圆心的距离startangle180, # 设置饼图的初始角度radius1.3, # 设置饼图的半径counterclockFalse, # 是否逆时针这里设置为顺时针方向wedgeprops{linewidth: 1.5, edgecolor: red}, # 设置饼图内外边界的属性值# textprops{fontsize: 10, color: black}, #设置文本标签的属性值)# 添加图标题self.F2.axes.set_title(情感倾向占比图)self.F2.fig.legend()# self.F2.fig.tight_layout()self.gridlayout2.addWidget(self.F2, 0, 0)self.gridlayout2.update()print(positive)