0
下面的代码已经从here采取和修改,以适应我的要求:使用Func键动画蟒蛇
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
import math
import linecache
fig = plt.figure()
ax = plt.axes(xlim=(0,600), ylim=(0,600))
line, = ax.plot([], [], lw=3, color='r')
mul=2*math.pi/3
samp_rate=10
print ax
def init():
line.set_data([], [])
return line,
def animate(i):
print i
global mul
global samp_rate
line1=linecache.getline("data.txt", i+1)
if i==0:
x = float(line1)*math.cos(0)
y = float(line1)*math.sin(0)
line.set_data(x, y)
return line,
else:
x=float(line1)*math.cos((i)*mul/samp_rate)
y=float(line1)*math.cos((i)*mul/samp_rate)
line.set_data(x, y)
return line,
anim = animation.FuncAnimation(fig, animate, init_func=init, interval=5, blit=True)
plt.show()
上打印斧头给出的输出如下:
Axes(0.125,0.1;0.775x0.8)
我设置值从0到600,但是限制是0.775 to 0.8
?这是为什么? 另外,我正在密谋值从100到400和输出窗口:
我要去哪里错了?
EDIT 1:
我改变了代码比特。现在,我从列表中输入值,即,我不打开文件的值,我只是用值创建一个列表。该代码是:
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
import math
import linecache
# First set up the figure, the axis, and the plot element we want to animate
fig = plt.figure()
ax = plt.axes(xlim=(0,600), ylim=(0,600))
line, = ax.plot([], [], lw=3, color='r')
mul=2*math.pi/3
samp_rate=10
print ax
def init():
line.set_data([], [])
return line,
def animate(i):
print i
global mul
global samp_rate
line1=linecache.getline("data.txt", i+1)
x=[some vlaues that I have to plot]
y=[some vlaues that I have to plot]
line.set_data(x, y)
i+=1
return line,
anim = animation.FuncAnimation(fig,animate,init_func=init,frames=200,interval=24,blit=True)
plt.show()
在这种情况下,输出如下:
而且,因为我马上打印的i
值作为我进入功能动画提供的输出不断增加。
我已经为x提供了约20k的值,并为y提供了相同数量的值。正如你在屏幕截图中看到的那样,并不是将它们全部绘制在一起。我如何绘制所有点?
我调试,发现'line1'是我的预期。还有什么可以出错? –