Animated graphs in ipython notebook

前端 未结 8 782
失恋的感觉
失恋的感觉 2020-12-30 02:01

Is there a way of creating animated graphs. For example showing the same graph, with different parameters.

For example is SAGE notebook, one can write:



        
8条回答
  •  感情败类
    2020-12-30 02:55

    This has horrible flickering, but at least this creates a plot that animates for me. It is based on Aron's, but Aron's does not work as-is.

    import time, sys
    from IPython.core.display import clear_output
    f, ax = plt.subplots()
    
    n = 30
    x = array([i/10.0 for i in range(n)])
    y = array([sin(i) for i in x])
    for i in range(5,n):
      ax.plot(x[:i],y[:i])
      time.sleep(0.1)
      clear_output()
      display(f)
      ax.cla() # turn this off if you'd like to "build up" plots
    plt.close()
    

提交回复
热议问题