For a long time, I have been struggling with the live portability of Matplotlib. In between, I moved to PyQt and found several good solutions there. However, now I'd like to write some very simple simulations and would like to keep track of the process. The data that has to be tracked is a 2D point, so I would use Matplotlib's scatter method. The updating works quite nicely with fig.canvas.draw. However the more data points I have plotted the slower the plotting becomes.
def __init__(self):
self.fig, (self.ax1, self.ax2) = plt.subplots(2)
self.fig.show()
self.fig.canvas.draw()
self.main()
def main(self):
c = 1
for i in range(1000):
self.ax1.scatter(i, c)
self.ax2.scatter(c, i)
c += 1
self.fig.canvas.draw()
self.fig.canvas.flush_events()
The relevant code lines are shown. It really revolves around the ax.scatter()
. To my understanding, the underlying plot object becomes larger and larger as continuously add points to a point where the plotting takes more time than actual data simulation. Is there a way to only plot the new points? I've read of options for line plots where people use line.set_ydata
and manual axis updates. Is there something similar to scatterplots or is there may be an even more elegant way?