先描述一下问题:
在QCombobox 的响应中我链接了函数tab_select(),但是这个函数中的绘图命令并未执行。
然后又尝试了直接调用函数tab_select(),绘图命令成功执行。
请问我应该怎么解决这个问题
#######
class MainApp(QMainWindow, Ui_MainWindow):
def init(self, parent=None):
super().init(parent)
Ui_MainWindow.init(self)
self.setupUi(self)
l = QVBoxLayout(self.widget)
self.fi = TabPlot()
l.addWidget(self.fi)
self.widget.setFocus()
self.setCentralWidget(self.tabWidget)
# self.tab_select()
self.comboBox.activated.connect(self.tab_select)
def tab_select(self):
getdata = mysqldata.Getdata()
time1 = self.spinBox.value()
time2 = self.spinBox_2.value()
name = self.comboBox.currentText()
data_check = getdata.tabData(name, time1, time2)
year = data_check[0]
data = data_check[1]
self.fi.tab_plot(year, data, name)
print(1, name, year, data)
class TabPlot(FigureCanvas):
def init(self):
# 画布上初始化一个图像
self.figure = Figure(figsize=(250, 750), dpi=100)
super().init(self.figure)
def tab_plot(self, year, data, name):
year = year
data = data
name = name
axes = self.figure.add_subplot(111)
plt.rcParams['font.sans-serif'] = ['SimHei'] # 设置中文字体
axes.set_xlabel("年份")
axes.set_ylabel(name)
axes.plot(year, data, color='red', marker='*', linestyle='--')