1

I would like to plot many lineplots in a loop in a jupyter notebook, and see the updates as the loop progresses. I want a single figure with many overlayed lineplots in it. If I do something like

import seaborn as sns
for i in range(N):
    x_data, y_data = get_data(i)
    sns.lineplot(x_data, y_data)

then the plot only shows up once the loop is finished. If I stick a plt.pause(1) in the loop like I've seen in related questions, then I get multiple figures. How can I do this?

theQman
  • 1,690
  • 6
  • 29
  • 52
  • You can use the sleep function in the time module as an alternative to `plt.pause` https://stackoverflow.com/questions/510348/how-can-i-make-a-time-delay-in-python – iamchoosinganame Jun 03 '19 at 19:58
  • Stick a 'time.sleep(1)' in the loop doesn't draw the plot until the loop is finished. – theQman Jun 03 '19 at 20:06
  • @iamchoosinganame No, the `time.sleep` function is in *no way* an alternative to `plt.pause()`! – ImportanceOfBeingErnest Jun 03 '19 at 20:06
  • Inline animations: https://stackoverflow.com/questions/35532498/animation-in-ipython-notebook/46878531#46878531 Alternatives: https://stackoverflow.com/questions/45724548/display-animation-outside-of-jupyter-notebook/45731293#45731293 – ImportanceOfBeingErnest Jun 03 '19 at 20:08

0 Answers0