1
私は4つの列を含むcsvファイルを持っています。時間の最初の列、2番目、3番目、4番目の列は加速度計の読みです。私はX軸上の時間とY軸上の加速度計の読みをプロットしたいと思います。
サンプルデータ:CSVからcoulmnsを読み込んでグラフをプロットする
0 1.0969 9.7721 0.614
20 1.1146 9.7501 0.7444
40 1.1146 9.7501 0.7444
60 1.0124 9.7151 0.7169
79 1.0124 9.7151 0.7169
100 1.0927 9.7324 0.7356
120 1.0927 9.7324 0.7356
ここでは、私がこれまで持っているものです。
from numpy import genfromtxt
import csv
import matplotlib.pyplot as plt
#import numpy as np
# Open the desired file for reading
f = open('walk-shoe.csv', "rb")
# create a object of csv class and read the file
# use ',' as a delimiter
reader = csv.reader(f, delimiter=',')
time_row = 0
accel_1_row = 0
accel_2_row = 0
accel_3_row = 0
time = []
accel_1 = []
accel_2 = []
accel_3 = []
# create a list of 'Time in ms'
for row in reader:
# Skip the first row
time_row = time_row + 1
if time_row == 1:
continue
time.append(row[0])
accel_1.append(row[1])
accel_2.append(row[2])
accel_3.append(row[3])
# print the contents of the list
# print time
#print accel_1
#print accel_2
#print accel_3
# append all the list accelerometer list together
final_accel = []
final_accel.append(accel_1)
final_accel.append(accel_2)
final_accel.append(accel_3)
#print final_accel
# plot the graph
for i in range(len(final_accel)):
plt.plot(time,[pt[i] for pt in final_accel],label = 'id %s'%i)
plt.legend()
plt.show()
私はので、私はあることを意味することがかかります、あなたはあなたが与えるコードでnumpyのを輸入しているように見える
'とValueError xおよびyは同じ第1の寸法を有するが、shapes'が最も頻繁にエラーのいずれかである必要があります。あなたはそれをGoogleにしましたか? 3つの値を1001にプロットしようとしています。どちらがうまくいかないでしょうか。 – ImportanceOfBeingErnest
すぐにお返事ありがとうございます。試しましたが、適切な解決策が見つかりませんでした。 – mgmihir
なぜですか?どんな解決法でも基本的にxとyの値と異なる長さのリストをプロットしようとはしません。 – ImportanceOfBeingErnest