3

I have 12 columns in my .dat file. How can I plot the first column with 12th column and there are around 50 rows. Each value is separated by a tab space. I have tried this error as the wrong number of columns at line42 is coming.

 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()  

1 Answer 1

3

The code in the question is correct! If it doesn't work, it's because your data is not organized the way you think it is or because you have missing values somewhere in your data.

You may try to use numpy.genfromtxt(...) which has more options for bad data filtering than np.loadtxt.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.