|  | 
 
| 本帖最后由 matlab的旋律 于 2020-9-22 14:38 编辑 
 复制代码import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
from PyQt5 import QtGui
from PyQt5 import uic
import numpy as np
class mainFunc():
    '类的帮助信息'  # 类文档字符串
    def __init__(self):
        self.ui = uic.loadUi("testUI.ui")
        self.ui.setWindowIcon(QtGui.QIcon("1.jpg"))
        self.ui.begin_tag.setCheckable(True)
        self.ui.begin_tag.clicked[bool].connect(self.plotFunc)
    def plotFunc(self, pressed):
        x = np.arange(0, 10, 0.2)
        print(pressed)
        if pressed:
            y1 = np.sin(x)
            y2 = np.cos(x)
            self.ui.begin_tag.setFont(QtGui.QFont("Arial", 20))#修改开始控件字体
        else:
            y1 = np.sinh(x)
            y2 = np.cosh(x)
            self.ui.begin_tag.setFont(QtGui.QFont("Arial", 10))#修改开始控件字体
        #画图前线清空
        self.ui.sin_tag.clear()
        self.ui.cos_tag.clear()
        self.ui.sin_tag.plot(x, y1, pen='r', symbol='o')# 绘图
        self.ui.cos_tag.plot(x, y2, pen='g', symbol='d')# 绘图
        self.ui.sin_tag.setTitle('正弦图')# 设置图表标题
        self.ui.cos_tag.setTitle('余弦图', color='r')# 设置图表标题
        # 设置上下左右的label
        self.ui.sin_tag.setLabel("left", "幅度")
        self.ui.sin_tag.setLabel("bottom", "时间")
        # 设置上下左右的label
        self.ui.cos_tag.setLabel("left", "幅度")
        self.ui.cos_tag.setLabel("bottom", "时间")
        # 设置Y轴 刻度 范围
        self.ui.sin_tag.setYRange(min=np.min(y1), # 最小值
                          max=np.max(y1))  # 最大值
        self.ui.cos_tag.setYRange(min=np.min(y2), # 最小值
                          max=np.max(y2))  # 最大值
        # 显示表格线
        self.ui.sin_tag.showGrid(x=True, y=True)
        self.ui.cos_tag.showGrid(x=True, y=True)
        # 背景色
        self.ui.sin_tag.setBackground('y')
        self.ui.cos_tag.setBackground('k')
if __name__ == '__main__':
    app = QApplication(sys.argv)
    ecgFig = mainFunc()
    ecgFig.ui.show()
    sys.exit(app.exec_())
 
 | 
 
x本帖子中包含更多资源您需要 登录 才可以下载或查看,没有帐号?立即注册  |