Aug-13-2020, 08:13 PM
I am trying to update a plot as fast as possible. The quickest way I found so far is in this post, where a line plot updates very quickly using a while loop. This is the code that updates a line amazingly fast:
Now I want to include text (which updates as quickly as the lines) in the plot (it can be within the plot area, eg like a legend) or as the title of the plot, both would be fine. I tried different ways but it doesn't work (text is updated only when the loop ended).
Is there a way to update text as quickly as line? (as mentioned, updating a set.text or alike within the while loop does not work)
import time import numpy as np import matplotlib.pyplot as plt fig, ax = plt.subplots() line, = ax.plot(np.random.randn(100)) fig.canvas.draw() plt.show(block=False) tstart = time.time() num_plots = 0 while time.time()-tstart < 5: line.set_ydata(np.random.randn(100)) ax.draw_artist(ax.patch) ax.draw_artist(line) fig.canvas.blit(ax.bbox) fig.canvas.flush_events() num_plots += 1
Now I want to include text (which updates as quickly as the lines) in the plot (it can be within the plot area, eg like a legend) or as the title of the plot, both would be fine. I tried different ways but it doesn't work (text is updated only when the loop ended).
Is there a way to update text as quickly as line? (as mentioned, updating a set.text or alike within the while loop does not work)