매끄러운 선과 같은 그래프를 그릴 때 matplotlib를 사용하고 있습니다. 나를 그리는 것은 문제가 아니지만 애니메이션에 문제가 있습니다.부드럽고 매끄러운 그림 선 파이썬 matplotlib
import numpy as np
import random as random
from matplotlib import pyplot as plt
from matplotlib import animation
그래서, 나는 다음과 같은 배열이 있습니다
a = [0,1,2,4,5,8,9,12,14,18,22,17,30,37,29,45]
을 그리고 나는 그것을 부드럽게 지점을 그릴 필요가있다. ,
# First set up the figure, the axis, and the plot element we want to animate
fig = plt.figure()
ax = plt.axes(xlim=(0, 50), ylim=(0, 50))
line, = ax.plot([], [], lw=2)
global x
global y
global n
global a
n=5
a = [0,1,2,4,5,8,9,12,14,18,22,17,30,37,29,45]
global desty,destx
desty = np.linspace(0,0,n)
destx = np.linspace(0,0,n)
for i in range(len(a)-1):
desty = np.append(desty,np.linspace(a[i],a[i+1],n))
destx = np.append(destx,np.linspace(i,i+1,n))
# initialization function: plot the background of each frame
def init():
line.set_data([], [])
return line,
# animation function. This is called sequentially
def animate(i):
global destx
global desty
x=destx
y=desty
line.set_data(x, y)
return line,
# call the animator. blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=200, interval=20, blit=True)
plt.show()
날 만 그릴 수 있습니다 : 나를
전체 코드 문제없이 선 (및 애니메이션을 :)) 그릴 수
for i in range(len(a)-1):
desty = np.append(desty,np.linspace(a[i],a[i+1],n))
destx = np.append(destx,np.linspace(i,i+1,n))
: 지금 나는이 문자열을 가지고 하지만 어떻게하면 느리고 부드러운 지점을 그릴 수 있습니까? 내가 파이썬 2.7를 사용하고
, CentOS는 7
'matplotlib.animation' API를 알려 주셔서 감사합니다. – heltonbiker
감사합니다. 그게 효과가있어, 나 아주 도와 줘! – shatalov