【问题标题】:Plot 3 selected random number of time-series data绘制 3 选择的时间序列数据的随机数
【发布时间】:2020-03-08 21:01:44
【问题描述】:

我有一个包含 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()

我的数据快照如下所示:

这就是我的情节的样子:

【问题讨论】:

    标签: python plot time-series


    【解决方案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()
    

    我没有你的数据,所以它无法运行代码来查看情节。如果出现任何错误,请告诉我

    【讨论】:

    • 嗨 ssssoooo 我想我的问题还不清楚。我有 9 类数据,每个类有 50 多个时间序列。我想要做的是绘制所有课程,但每个课程有 3 个时间序列。我会将我的数据快照添加到问题中。
    猜你喜欢
    • 1970-01-01
    • 2014-09-23
    • 1970-01-01
    • 2020-04-09
    • 2020-10-13
    • 2022-01-09
    • 2013-12-25
    • 2011-03-19
    相关资源
    最近更新 更多