动画不显示使用matplotlib传递的参数

时间:2019-07-17 15:44:49

标签: python matplotlib animation

我已经采用了一个代码,该代码绘制了许多粒子的场线,现在我想为一个点移动时改变其颤动的动画。该脚本显示空白图片。

我曾经尝试过使用matplotlib动画,但是我认为问题在于y如何传递参数。这是我当前的代码

import numpy as np
import matplotlib.pyplot as plt
import math as ma
from matplotlib import animation

np.seterr(divide='ignore', invalid='ignore')

fig, ax = plt.subplots(1,1)
def seno(a,p,x):
    return (int(a*ma.sin(p*x)+7))
# grid size
N = 15
M = 25
ax.set_xlim(0, M)
ax.set_ylim(0, N)

# coordinates
X = np.arange(0, M, 1)
Y = np.arange(0, N, 1)
X, Y = np.meshgrid(X, Y)
# strength
Ex = np.zeros((N, M))
Ey = np.zeros((N, M))
# amount of charges


# computing
qq = [[], []]  # to store charges coordinates

def arrows(q,qx,qy,Ex,Ey,qq):
    qq[0].append(qy)
    qq[1].append(qx)
    for i in range(N):
        for j in range(M):
            denom = ((i - qx) ** 2 + (j - qy) ** 2) ** 1.5
            if denom != 0: 
                Ex[i, j] += q * (j - qy) / denom
                Ey[i, j] += q * (i - qx) / denom
    E = (Ex ** 2 + Ey ** 2) ** .5
    Ex = Ex / E
    Ey = Ey / E

def mover(qx,qy,q,Ex,Ey):
    for i in range(N):
        for j in range(M):
            denom = ((i - q[1][1]) ** 2 + (j - q[0][1]) ** 2) ** 1.5
            if denom != 0: 
                Ex[i, j] -= (j - q[0][1]) / denom
                Ey[i, j] -= (i - q[1][1]) / denom
    q[0].pop()
    q[1].pop()
    arrows(1,qx,qy,Ex,Ey,q)
    E = (Ex ** 2 + Ey ** 2) ** .5
    Ex = Ex / E
    Ey = Ey / E
arrows(-1,7,25,Ex,Ey,qq)
arrows(1,7,3,Ex,Ey,qq)
C = np.hypot(Ex, Ey)



C = np.hypot(Ex, Ey)
# normalized values for arrows to be of equal length




def animate(i,args):
    mover(7,seno(args[0],args[1],i))
    ax.plot(*qq, 'bo')
    ax.quiver(X, Y, Ex, Ey, C, pivot='mid')

anim = animation.FuncAnimation(fig, animate, (4,1), frames=200, interval=20, blit=True)


plt.show()

我希望在移动点时为其动画,这会改变颤动。

0 个答案:

没有答案