How to build from .dat file with multiple columns and rows separated by spaces
I have 12 columns in my .dat file. How can I plot the first column with 12th column and about 50 rows. Each value is separated by a tab space. I tried this error as it comes up with the wrong number of columns in row42.
import numpy as np
from matplotlib import pyplot as plt
data=np.loadtxt('filep.dat')
pl.plot(data[:,1],data[:,2],'bo')
X=data[:,1]
Y=data[:,2]
plt.plot(X,Y,':ro')
plt.show()
+3
source to share
1 answer
The code in the question is correct! If that doesn't work, it is because your data is not organized the way you think it is, or because you are missing values somewhere in your data.
You can try to use numpy.genfromtxt(...)
which has more power to filter out bad data than np.loadtxt
.
+3
source to share