一个想法是在第一个绘图完成后仅更新图形对象.
axes.plot应返回一个Line2D对象,您可以修改其x和y数据:
因此,一旦绘制了线条,不要删除并绘制新线条,而是修改现有线条:
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()