我使用“滚动图”示例作为pyqtgraph.examples模板来创建一个图,该图显示了连续的正弦波。现在,我想使用按钮来改变正弦波的幅度。这就是我使用另一种结构的原因(参见下面的代码)。这不起作用,它只绘制静态正弦波。如何使用更新函数绘制连续正弦波?如何使用按钮更改幅度?我已经检查过这个和这个但没有成功。
import sys
from PyQt4 import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
class sinus_wave(QtGui.QWidget):
def __init__(self):
super(sinus_wave, self).__init__()
self.initUI()
def initPlot(self, plots):
a = 10
ptr1 = 30
data1 = a*np.sin(np.linspace(0,30,121))
plots.plot(data1)
timer = pg.QtCore.QTimer()
timer.timeout.connect(lambda: self.update(self,p1 = plots,data1= data1, ptr1 = ptr1))
timer.start(50)
def initUI(self):
IncreaseButton = QtGui.QPushButton("Increase Amplitude")
DecreaseButton = QtGui.QPushButton("Decrease Amplitude")
p1 = pg.PlotWidget()
hbox = QtGui.QVBoxLayout()
hbox.addWidget(p1)
hbox.addWidget(IncreaseButton)
hbox.addWidget(DecreaseButton)
self.initPlot(p1)
self.setLayout(hbox)
self.setGeometry(10, 10, 1000, 600)
self.setWindowTitle('Sinuswave') …Run Code Online (Sandbox Code Playgroud)