我希望通过从文件中读取数据来将图形显示为幻灯片。首先我希望绘制第一组数据,然后绘制下一组数据,依此类推。 我试过的是:
class MatplotlibWidget(QMainWindow):
def __init__(self):
---
self.playbutton.clicked.connect(self.drawGraph)
self.pausebutton.clicked.connect(self.pauseGraph)
----
def drawGraph(self):
f1 = open('TESTIP2.txt', 'r')
data = np.genfromtxt(f1)
m = np.size(data, 0)
n = np.size(data, 1)
x = data[:, 0].reshape(m, 1)
y = data[:, 1].reshape(m, 1)
iters = m // 4
current_iter=0
self.plotGraph(x,y,iters,current_iter)
def plotGraph(x,y,iters,current_iter):
for i in range(iters):
self.plotDraw(x[current_iter:current_iter+iters],y[current_iter:current_iter+iters])
current_iter=current_iter+iters
time.sleep(1)
def plotDraw(x,y)
self.MplWidget.canvas.axes.clear()
self.MplWidget.canvas.axes.plot(x,y)
self.MplWidget.canvas.axes.legend(('cosinus', 'sinus'), loc='upper right')
self.MplWidget.canvas.axes.set_title('Signal' )
self.MplWidget.canvas.draw()
在循环内调用plotDraw函数以显示每组数据,但其仅显示最后一组数据。有没有办法在特定的时间间隔后显示第一个、第二个等等。你知道吗
最简单的方法是使用来自} 。这真的很容易使用:您指定了一个应该在超时后触发的函数,并指定了时间间隔。使用下面的代码,我在
PyQt5
的^{PyQt5
内的Matplotlib小部件中每秒绘制一次随机数据。你知道吗上面的代码提供了以下信息:
例如,您可以使用按钮触发
self.t.stop()
来停止更新/循环,如果您想继续,您可以再次self.t.start(your_interval)
。你知道吗相关问题 更多 >
编程相关推荐