我有一组我已经生成的速度,我想绘制它们如何随时间变化(如股票的时间序列)。我希望数组中的每个元素在给定时间/帧的每一行都是一个点。我的代码与此类似:
from matplotlib import pyplot as plt
import numpy as np
import random
from matplotlib import cm
from celluloid import Camera
n = 10 #number of lines I want to generate
def generate_velocities(n): #generate 10 different velocities
return [random.randint(0, 5) for i in range(n)] #velocities between 0 and 5
camera = Camera(plt.figure())
colours = cm.rainbow(np.linspace(0, 1, n)) #each lines' colour
frames = 50
t = np.arange(frames) #time to equal the same number of frames
for i in range(frames):
v = generate_velocities(n)
plt.plot(t, v, c=colours)
camera.snap()
但是自然地,v 和 t 的形状不同,即便如此,我认为这不会生成我想要的图形。我将如何使其适应工作?