简体   繁体   English

Plot 3 个随机选择的时序数据

[英]Plot 3 selected random number of time-series data

I have a time series data with 9 classes and would like to show 3 randomly selected time series of each class.我有一个包含 9 个类的时间序列数据,并且想显示每个 class 的 3 个随机选择的时间序列。

Code below plots all the data.下面的代码绘制了所有数据。 My questions are:我的问题是:

1) What is the meaning of the part inside the brackets in this line ( for x in X[y == (i+1)]: )? 1)这一行括号内的部分是什么意思( for x in X[y == (i+1)]: )?

2) How I can plot 3 times series of each class and not all the data? 2)我怎样才能 plot 每个 class 的 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()

snapshot of my data looks like this:我的数据快照如下所示:

在此处输入图像描述

And this is how my plots look like:这就是我的情节的样子:

在此处输入图像描述

1-about your first question i what in Y and X i your code?i think that part is for plotting a time series elements but since i dont know your data i cant answer clearly 2- about second part i suggest to generate 3 random numbers between 1,9 which they are your series and put this list in your plot, like here. 1-关于您的第一个问题,我的代码中 Y 和 X 是什么?我认为这部分是用于绘制时间序列元素,但由于我不知道您的数据,我无法清楚地回答 2-关于第二部分,我建议生成 3 个随机数在 1,9 之间,它们是您的系列,并将此列表放入您的 plot 中,就像这里一样。


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()

i dont have your data so i couldnt run the code to see the plot.if it gives any error let me know我没有你的数据,所以我无法运行代码来查看 plot。如果出现任何错误,请告诉我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM