资源简介
本资源为PyQt5,charts绘制折线图的基础上,进行实时刷新折线图,或者动态折线/曲线。
代码片段和文件信息
import os
import time
import sys
FileName = os.path.basename(sys.argv[0])
FilePath = sys.argv[0].replace(FileName““)
UiName = FileName.replace(“.py““.ui“)
UiPath = FilePath +UiName
Ui_pyName = FilePath+“ui.py“
FileFlag = os.path.isfile(Ui_pyName)
if FileFlag == 0:
sys_cmd = os.popen(“pyuic5“+“ -o “+Ui_pyName+“ “+UiPath)
time.sleep(1)
from ui import Ui_Form
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtChart import *
import random
DataVector = []
mutex = QMutex()
class ThreadCtl(QThread):
def __init__(self):
super().__init__()
self.threadstatus = 1
def run(self):
while self.threadstatus == 1:
self.randdata_h = random.uniform(1 6)
self.randdata_h = round(self.randdata_h 2)
# self.randdata_w = random.uniform(1 6)
# self.randdata_w = round(self.randdata_w 2)
# self.points = [self.postself.randdata_h]
time.sleep(1)
mutex.lock()
DataVector.append(self.randdata_h)
mutex.unlock()
print(“DataVector:“DataVector)
class m_window(QWidgetUi_Form):
def __init__(self):
super(m_windowself).__init__()
self.setupUi(self)
self.threadCtl = ThreadCtl()
self.threadCtl.start()
self.timer = QTimer()
self.timer.timeout.connect(self.update)
self.timer.start(2000)
self.ctl = 0
self.series_1 = QLineSeries() #定义LineSerise,将类QLineSeries实例化
self._1_point_0 = QPointF(0.000.00) #定义折线坐标点
self._1_point_1 = QPointF(0.806.00)
self._1_point_2 = QPointF(2.002.00)
self._1_point_3 = QPointF(4.003.00)
self._1_point_4 = QPointF(1.003.00)
self._1_point_5 = QPointF(5.003.00)
self._1_point_list = [self._1_point_0self._1_point_1self._1_point_4self._1_point_2self._1_point_3self._1_point_5] #定义折线清单
self.series_1.append(self._1_point_list) #折线添加坐标点清单
self.series_1.setName(“折线一“)
self.series_2 = QLineSeries() #定义LineSerise
self._2_point_0 = QPointF(0.000.00) #定义折线坐标点
self._2_point_1 = QPointF(0.505.00)
self._2_point_2 = QPointF(2.001.00)
self._2_point_3 = QPointF(4.002.00)
self._2_point_4 = QPointF(1.002.00)
self._2_point_5 = QPointF(5.002.25)
self._2_point_list = [self._2_point_0self._2_point_1self._2_point_4self._2_point_2self._2_point_3self._2_point_5] #定义折线清单
self.series_2.append(self._2_point_list) #折线添加坐标点清单
self.series_2.setName(“折线二“)
self.series_3 = QLineSeries() #定义LineSerise
# self.series_3.append(2.223.45)
# self.series_3.append(3.455.23)
self.x_Aix = QValueAxis()
self.x_Aix.setRange(0.005.00)
self.x_Aix.setLabelFormat(“%0.2f“)
self.x_Aix.setTickCount(6)
self.x_Aix.setMinorTickCount(0)
self.y_Aix = QValueAxis()
self.y_Aix.setRange(0.006.00)
self.y_Aix.setLabelFormat(“%0.2f“)
self.y_Aix.setTickCount(7)
self.y_Aix.setMinorTickCount(0)
self.charView = QChartView(self) #定义charView,父窗体类型为 Window
self.setLayout(self.gridLayout)
self.gridLayout.addWidget(self.charView
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-03-31 15:21 chars\.vs\
目录 0 2019-03-31 15:21 chars\.vs\chars\
目录 0 2019-03-31 15:21 chars\.vs\chars\v15\
文件 36864 2019-10-07 13:23 chars\.vs\chars\v15\.suo
文件 950 2019-03-31 15:21 chars\chars.sln
目录 0 2019-10-04 21:23 chars\chars\
目录 0 2019-08-11 10:45 chars\chars\__pycache__\
文件 994 2019-08-11 10:45 chars\chars\__pycache__\ui.cpython-36.pyc
文件 4977 2019-10-04 21:23 chars\chars\chars.py
文件 1516 2019-03-31 15:21 chars\chars\chars.pyproj
文件 552 2019-08-11 10:45 chars\chars\chars.ui
文件 956 2019-08-11 10:45 chars\chars\ui.py
- 上一篇:文本文件单词的检索与计数
- 下一篇:编译原理实验 中间代码优化 代码 报告
评论
共有 条评论