2016-11-09 6 views
2

中の極性円のアニメーションが永続的に、膨張・縮小、円、のための振動ダイナミクスをシミュレートするために私のpythonファイルです:ここでのpython

import numpy as np 
from matplotlib import pyplot as plt 
from matplotlib import animation 

fig = plt.figure() 
ax = plt.axes(xlim=(0, 2), ylim=(-2, 2)) 
line, = ax.plot([], [], lw=2) 

def init(): 
    line.set_data([], []) 
    return line, 

def animate(i): 
    theta = np.linspace(0, 2 * np.pi, 100) 
    r = np.sqrt(np.abs(np.sin(0.1 * i))) 
    x = r * np.cos(theta) + 1 
    y = r * np.sin(theta) 
    line.set_data(x, y) 
    return line, 

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

plt.show() 

しかし、パラメトリック定義には欠陥がある、などという結果ISN」ですアニメーションサークルですが、省略記号です。

どうすれば修正できますか?

答えて

4

plt.gca().set_aspect('equal', adjustable='box')を追加しようとすると、次のようにあなたのylimを変更:

import numpy as np 
from matplotlib import pyplot as plt 
from matplotlib import animation 

fig = plt.figure() 
ax = plt.axes(xlim=(0, 2), ylim=(-1, 1)) 
line, = ax.plot([], [], lw=2) 

def init(): 
    line.set_data([], []) 
    return line, 

def animate(i): 
    theta = np.linspace(0, 2 * np.pi, 100) 
    r = np.sqrt(np.abs(np.sin(0.1 * i))) 
    x = r * np.cos(theta) + 1 
    y = r * np.sin(theta) 
    line.set_data(x, y) 
    return line, 

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

plt.gca().set_aspect('equal', adjustable='box') 
plt.show() 

次のようにこれはそれを表示していました:

equal axis screenshot

3

をあなたの軸は同じ長さ(バウンディングボックス)を持っていません試してみてください:

import numpy as np 
from matplotlib import pyplot as plt 
from matplotlib import animation 

fig = plt.figure() 
ax = plt.axes(xlim=(-2, 2), ylim=(-2, 2)) 
line, = ax.plot([], [], lw=2) 

def init(): 
    line.set_data([], []) 
    return line, 

def animate(i): 
    theta = np.linspace(0, 2 * np.pi, 100) 
    r = 2*np.sqrt(np.abs(np.sin(0.1 * i))) 
    x = r * np.cos(theta) 
    y = r * np.sin(theta) 
    line.set_data(x, y) 
    return line, 

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

plt.show()