How to animate a scatter plot?

后端 未结 4 1878
清酒与你
清酒与你 2020-11-22 17:18

I\'m trying to do an animation of a scatter plot where colors and size of the points changes at different stage of the animation. For data I have two numpy ndarray with an x

4条回答
  •  醉梦人生
    2020-11-22 18:03

    Why Not try this

    import numpy as np
    import matplotlib.pyplot as plt
    
    x=np.random.random()
    y=np.random.random()
    
    fig, ax = plt.subplots()
    ax.scatter(x,y,color='teal')
    ax.scatter(y,x,color='crimson')
    ax.set_xlim([0,1])
    ax.set_ylim([0,1])
    
    for i in np.arange(50):
        x=np.random.random()
        y=np.random.random()
        bha=ax.scatter(x,y)
        plt.draw()
        plt.pause(0.5)
        bha.remove()
    
    plt.show()
    

提交回复
热议问题