帮我写一段PYQT5上位机显示波形曲线的代码
时间: 2023-03-25 19:04:32 浏览: 153
以下是一段PYQT5上位机显示波形曲线的代码:
```python
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtGui import QPainter, QPen
import numpy as np
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("波形曲线显示")
self.setGeometry(100, 100, 800, 600)
self.data = np.zeros(100)
self.timer = QTimer(self)
self.timer.timeout.connect(self.update_data)
self.timer.start(50)
def update_data(self):
self.data = np.roll(self.data, -1)
self.data[-1] = np.random.randint(, 100)
def paintEvent(self, event):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.setPen(QPen(Qt.red, 2))
for i in range(len(self.data) - 1):
x1 = i * 8
y1 = 500 - self.data[i] * 4
x2 = (i + 1) * 8
y2 = 500 - self.data[i + 1] * 4
painter.drawLine(x1, y1, x2, y2)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
```
希望能对你有所帮助!
阅读全文