代码之家  ›  专栏  ›  技术社区  ›  Dhruv Chadha

Matplotlib中面片的平滑颜色更改动画

  •  1
  • Dhruv Chadha  · 技术社区  · 7 年前
    import numpy as np
    import matplotlib
    import matplotlib.pyplot as plt
    from matplotlib.patches import Circle
    from matplotlib import animation
    
    matplotlib.rcParams["figure.figsize"]=(10, 5)
    
    fig, ax = plt.subplots()
    
    
    
    ax.axis("equal")
    ax.set_xlim(-2, 2)
    ax.set_ylim(-1, 1)
    
    
    
    def animate(i):
        circle1 = Circle((0.1, 0.1), 0.2, color = '#' + str(i)*6)
        circle2 = Circle((0.5, 0.5), 0.2, color = '#ffff00')        
        ax.add_artist(circle1);
        ax.add_artist(circle2);
    
    anim = animation.FuncAnimation(fig, animate, frames=9, interval=1000, blit=True)
    
    plt.show()
    

    在我的动画功能中,我正在尝试为我的第一个圆形面片从黑色平滑过渡到灰色。但是,它不起作用。有人能帮忙吗?此外,我还需要一个平滑的边界动画。是否可以为同一面片分别设置面颜色和边框颜色动画?如果是的话,怎么办?

    0 回复  |  直到 7 年前