简体   繁体   English

python plt.plot,不完整的indeces

[英]python plt.plot with incomplete indeces

p = [] 
for i in range(len(f)):
    p.append(peakdetect(H, 0.1)) 
plt.plot(Freq[p], f)

Because the whole code is complex so I only attach the part where the bug is. 因为整个代码很复杂所以我只附加了bug所在的部分。

I want to plot a graph about Freq and f. 我想绘制一个关于Freq和f的图表。 And p is the index shows below, p是下面的索引,

[[126, 269, 409, 542],
 [145, 288, 427, 558],
 [162, 305, 443, 572],
 [177, 320, 457],
 [191, 334, 471],
 [204, 347, 483],
 [217, 359, 494],
 [228, 370, 504],
 [238, 380, 513],
 [248, 389, 521],
 [257, 398, 528],
 [265, 406, 535],
 [273, 414, 541],
 [280, 421, 546],
 [287, 428, 551],
 [294, 434],
 [300, 440],
 [306, 445],
 [312, 451],
 [317, 455],
 [322, 460],
 [327, 464],
 [331, 468],
 [336, 472],
 [340, 476],
 [344, 479],
 [348, 482],
 [351, 486],
 [355, 488],
 [358, 491],
 [361, 494],
 [364, 496],
 [367, 498],
 [370, 500],
 [373, 502],
 [375, 504],
 [378, 506],
 [380, 507],
 [383, 509],
 [385, 510],
 [387, 511],
 [389, 512],
 [392, 513],
 [394, 514],
 [395, 515],
 [397, 515],
 [399, 516],
 [401, 516],
 [403],
 [404],
 [406],
 [408],
 [409],
 [411],
 [412],
 [413],
 [415],
 [416],
 [417],
 [419],
 [420]]

in which, 其中,

f[0] corresponds to [126, 269, 409, 542]
f[1] corresponds to [145, 288, 427, 558]
f[2] corresponds to [162, 305, 443, 572]
f[3] corresponds to [177, 320, 457]
f[4] corresponds to [191, 334, 471]

...

You see, the list p doesn't complete 4 columns, so when I run it, it shows the error: only integers, slices ( : ), ellipsis ( ... ), numpy.newaxis ( None ) and integer or boolean arrays are valid indices. 你看,一览P未完成4列,所以当我运行它,它显示了错误: 只有整数,切片( : ),省略号( ... ),numpy.newaxis( None )和整数或布尔数组是有效的指数。

So one way I think is to complete the rest of the column with None, but I'm not sure. 所以我认为有一种方法是使用None完成列的其余部分,但我不确定。 Another way is to slice the column but with list character, it's difficult to manipulate. 另一种方法是对列进行切片但是使用列表字符,很难操作。

peakdetect(H, 0.1) is a self-defined function. peakdetect(H,0.1)是一个自定义函数。 No worries for it. 不用担心。

Using pandas your problem is super easy to solve: 使用pandas你的问题非常容易解决:

import pandas as pd
a = [[126, 269, 409, 542],
 [145, 288, 427, 558],
 [162, 305, 443, 572],
 [177, 320, 457],
 [191, 334, 471],
 [204, 347, 483],
 [217, 359, 494],
 [228, 370, 504],
 [238, 380, 513],
 [248, 389, 521],
 [257, 398, 528],
 [265, 406, 535],
 [273, 414, 541],
 [280, 421, 546],
 [287, 428, 551],
 [294, 434],
 [300, 440],
 [306, 445],
 [312, 451],
 [317, 455],
 [322, 460],
 [327, 464],
 [331, 468],
 [336, 472],
 [340, 476],
 [344, 479],
 [348, 482],
 [351, 486],
 [355, 488],
 [358, 491],
 [361, 494],
 [364, 496],
 [367, 498],
 [370, 500],
 [373, 502],
 [375, 504],
 [378, 506],
 [380, 507],
 [383, 509],
 [385, 510],
 [387, 511],
 [389, 512],
 [392, 513],
 [394, 514],
 [395, 515],
 [397, 515],
 [399, 516],
 [401, 516],
 [403],
 [404],
 [406],
 [408],
 [409],
 [411],
 [412],
 [413],
 [415],
 [416],
 [417],
 [419],
 [420]]

df = pd.DataFrame(a)
df.plot()

在此输入图像描述

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

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