来自 matplotlib 变量的数据列表

List of data from matplotlib variables

我在matplotlib中使用了两个变量,其中一个是测量数据,第二个是0到300秒的时间尺度。我需要做的是制作一个垂直列表(都在一起,彼此相邻),以查看某个测量发生在什么时间。

使用 zip (Doku)。两个列表中较短的获胜,较长的列表中不匹配的项目将被丢弃:

l1 = ["1","2","3","4","5"]
l2 = ["a","aa","aaa","aaaa","aaaa","discard","discard2"]

l3 = zip(l1,l2) # relates same indexes in bot lists as tuple (l1[i],l2[i]) 

for tup in l3:
    print(tup[0], "  " , tup[1])

输出:

1    a
2    aa
3    aaa
4    aaaa
5    aaaa 

"vertical list" 可能已经是我在这里所说的 l3 - 它是包含(在您的情况下:(time, value)

的 2 元组列表

保存到文件:

with open("demodata.txt","w") as f: 
    for tup in l3:
        f.write(tup[0], "  " , tup[1],"\n")