Animated graphs in ipython notebook

前端 未结 8 787
失恋的感觉
失恋的感觉 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条回答
  •  旧时难觅i
    2020-12-30 02:56

    Update: January 2014

    Jake Vanderplas has created a Javascript-based package for matplotlib animations available here. Using it is as simple as:

     # https://github.com/jakevdp/JSAnimation
     from JSAnimation import examples
     examples.basic_animation()
    

    Example of Jake's JSAnimation package

    See his blog post for a more complete description and examples. Historical answer (see goger for a correction)

    Yes, the Javascript update does not correctly hold the image frame yet, so there is flicker, but you can do something quite simple using this technique:

    import time, sys
    from IPython.display import clear_output
    f, ax = plt.subplots()
    
    for i in range(10):
      y = i/10*sin(x) 
      ax.plot(x,y)
      time.sleep(0.5)
      clear_output()
      display(f)
      ax.cla() # turn this off if you'd like to "build up" plots
    plt.close()
    

提交回复
热议问题