2017-11-29 10 views
0

私は極プロットを作成し、ドップラーを模倣したいと思います。これには、円の周囲に360度の掃引が含まれます(極座標プロット)。スイープが360度になったら、ゼロに戻ってスイープを続ける必要があります。Matplotlibラインの回転またはアニメーション

この円を周回するようにこの線をアニメートまたは回転させるにはどうすればよいですか?私はただ一つの線が常にこのプロットの周りを掃くようにしたい。

私はいくつかの異なる例を見てきましたが、この回転を作成するものはありません。以下は

import numpy as np 
import math 
import matplotlib.pyplot as plt 
import pylab 
import time 

r = 90 * (math.pi/180) 
t = 50000 
az = 90 
el = 5 

fig = pylab.figure(figsize = [5.0, 5.0]) 
ax = fig.gca(projection = 'polar') 
fig.canvas.set_window_title('Doppler') 
ax.plot(r, t, color ='b', marker = 'o', markersize = '3') 
ax.set_theta_zero_location('N') 
ax.set_theta_direction(-1) 

currTime = time.time() 
prevTime = currTime - 1 
deltaTime = currTime - prevTime 

outer_border_width = 1 

screen_width = 500 
screen_height = 500 

midpoint = [int(screen_width/2), int(screen_height/2)] 
radius = (midpoint[0]) 
sweep_length = radius - outer_border_width 

angle = 50 
sweep_interval = 10 
sweep_speed = sweep_interval 

x = sweep_length * math.sin(angle) + int(screen_width/2) 
y = sweep_length * math.cos(angle) + int(screen_height/2) 

az = az + ((360.0/sweep_interval) * deltaTime) 

line1 = (midpoint, [50000, 50000]) 
#line2 = (midpoint, [20000, 20000]) 

ax.plot(line1, color = 'b', linewidth = 1) 

#Increase the angle by 0.05 radians 
angle = angle - sweep_speed 

#Reset the angle to 0 
if angle > 2 * math.pi: 
    angle = angle - 2 * math.pi 

#ax.plot(line2, color = 'r', linewidth = 1) 
#ax.lines.pop(0) 

plt.show() 

、それが現在の参照のためにどのように見えるかの写真です: enter image description here

多くの感謝!

答えて

1

私はあなたのコードの多くを理解していませんが、アニメーションを作成するにはmatplotlib.animation.FuncAnimationを使用できます。ここでは、各フレームのラインのデータを設定する更新関数のアレーの配列を与えます。

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

r = 90 * (np.pi/180) 
t = 50000 

fig = plt.figure() 
ax = fig.gca(projection = 'polar') 
fig.canvas.set_window_title('Doppler') 
ax.plot(r, t, color ='b', marker = 'o', markersize = '3') 
ax.set_theta_zero_location('N') 
ax.set_theta_direction(-1) 
ax.set_ylim(0,1.02*t) 

line1, = ax.plot([0, 0],[0,t], color = 'b', linewidth = 1) 

def update(angle): 
    line1.set_data([angle, angle],[0,t]) 
    return line1, 

frames = np.linspace(0,2*np.pi,120) 

fig.canvas.draw() 
ani = matplotlib.animation.FuncAnimation(fig, update, frames=frames, blit=True, interval=10) 

plt.show() 

enter image description here

関連する問題