pyQt Matplotlib widget live data updates

橙三吉。 提交于 2019-12-01 12:02:46
sebastian

One idea would be to update only the graphics object after the first plot was done. axes.plot should return a Line2D object whose x and y-data you can modify:

http://matplotlib.org/api/artist_api.html#matplotlib.lines.Line2D.set_xdata

So, once you have the line plotted, don't delete and plot a new one, but modify the existing:

def updateData(self):
    if not hasattr(self, 'line'):
        # this should only be executed on the first call to updateData
        self.ui.graph.axes.clear()
        self.ui.graph.axes.hold(True)
        self.line = self.ui.graph.axes.plot(self.ValueTotal,'r-')
        self.ui.graph.axes.grid()
    else:
        # now we only modify the plotted line
        self.line.set_xdata(np.arange(len(self.ValueTotal))
        self.line.set_ydata(self.ValueTotal)
    self.ui.graph.draw()
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!