2017-10-29 9 views
0

私の主な目標は、matplotlibを使ってラインプロットを作成することです。しかし毎回、散布図が得られます。 は、これは私のサンプルコードです:Matplotlibを使ったラインプロットの作成

import matplotlib.pyplot as plt 

def function(): 
    with open(filename) as f: 
      next(f) #i want to skip first line 
      for i,line in enumerate(f): 
       x=line.split(',') 
       a=[float (j) for j in x] #list 'a' now has float values not strings 

       OY=a[2:34] #creating list which will start from index 2 

       OX=a[1] #creating list which has only values with index 1 

       plt.plot(OX, OY,'-',color='red') 


    plt.show() 

function() 

残念ながら私は、散布図を得たが、私はラインプロットを期待しました。ここで何が間違っていますか?どうすれば変更できますか?

+1

同様の問題がありますか? https://stackoverflow.com/questions/46680194/matplotlib-plt-plot-with-enumerate-not-working/46680224#46680224 – Julien

+1

>「ValueError:xとyの最初の次元が同じでなければならない」 – nobar

答えて

0

あなたは、私はあなたのデータラインは、このフォームに従うと仮定してい

OX=numpy.arange(len(OY)) ## create a linear list of indexes 

...これで... ...

OX=a[1] ## results in ValueError: x and y must have same first dimension 

を置き換えることにより、ラインプロットを得ることができます...

2, 4, 8, 16, 32, 64, 128, 256 
+0

助けてくれてありがとう私の間違い、OXとOYは浮動小数点数を返しましたが、それはリストでなければなりません。私はそれを修正し、今は仕事です:) – Rocky3582

関連する問題