[英]How to update a matplotlib figure, from a function, in a Qt GUI
I have written a small GUI with qtdesigner and python which should display in real-time the trajectory of one particle in a matplotlib figure. 我用qtdesigner和python编写了一个小GUI,它应该实时显示matplotlib图中一个粒子的轨迹。 So I have something like: 所以我有类似的东西:
class DesignerMainWindow(QtGui.QMainWindow, Ui_MplMainWindow):
"""Customization for Qt Designer created window"""
def __init__(self, parent = None):
# initialization of the superclass
super(DesignerMainWindow, self).__init__(parent)
# setup the GUI --> function generated by pyuic4
self.setupUi(self)
self.niter = 30
#... other initializations
def run(self):
# set xo, yo with initial particle position
for t in range(self.niter):
# set new particle position in x, y
self.mpl.canvas.ax.plot([xo, x], [yo, y], '-b')
self.mpl.canvas.draw()
print x, y, t, self.niter
xo = x
yo = y
My problem is that the figure is updated only when the function "run()" is finished, despite the call to "draw()" inside the loop. 我的问题是,只有在函数“run()”完成时才更新数字,尽管在循环内调用了“draw()”。 Thus I have only the final trajectory and not the full movie... 因此,我只有最终的轨迹,而不是完整的电影......
Does anyone has an idea on how to force the graph update from within this function/loop ? 有没有人知道如何从这个函数/循环中强制图更新?
Thanks. 谢谢。
尝试在for
循环结束时调用QCoreApplication.processEvents()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.