我有一个9类的时间序列数据,想显示每个类的3个随机选择的时间序列。
下面的代码绘制了所有数据。我的问题是:
1)这行(for x in X[y == (i+1)]:
)中括号内的部分是什么意思?
2)如何绘制每个类的3次序列,而不是所有数据?
plt.figure(figsize=(12, 9))
for i, classe in enumerate(['1', '2', '3', '4', '5', '6', '7', '8', '9']):
plt.subplot(9, 1, i + 1)
plt.yscale('log')
for x in X[y == (i+1)]:
plt.plot(x, color='C0', linewidth=0.9)
plt.title('Class: {}'.format(classe), fontsize=16)
plt.tight_layout()
plt.subplots_adjust(hspace=0.4)
plt.show()
我的数据快照如下:
这是我的情节的样子:
答案 0 :(得分:1)
1-关于您的第一个问题,我的代码在Y和X中是什么?我认为该部分用于绘制时间序列元素,但由于我不知道您的数据,因此无法清晰回答 2-关于第二部分,我建议在1,9之间生成3个随机数,它们是您的序列,并将此列表放在您的绘图中,例如此处。
import random
rand1= random.randint(1, 9)
rand2= random.randint(1, 9)
rand3= random.randint(1, 9)
print(rand1,rand2,rand3)
#im not sure if this part is necesary but i wrote to be sure it follows your code pattern
rand1=str(rand1)
rand2=str(rand2)
rand3=str(rand3)
a=[rand1,rand3,rand2]
print(a)
plt.figure(figsize=(12, 9))
for i, classe in enumerate(a):
plt.subplot(len(a), 1, i + 1)
plt.yscale('log')
for x in X[y == (i+1)]:
plt.plot(x, color='C0', linewidth=0.9)
plt.title('Class: {}'.format(classe), fontsize=16)
plt.tight_layout()
plt.subplots_adjust(hspace=0.4)
plt.show()
我没有您的数据,所以我无法运行代码来查看绘图。如果出现任何错误,请告诉我