Reputation: 7
So far I have been trying to import poorly formated scientific notation data into a plot using python. I have tried variants of
import matplotlib.pyplot as plt
import numpy as np
data = np.genfromtxt("/home/rex/Documents/ModLab/PhotoElec/Exp2Data.csv",delimiter=',', unpack=True, names=True)
plt.axis([-1,32, 0 , 203])
plt.title('All Aperture')
plt.xlabel('Voltage')
plt.ylabel('Current')
plt.plot(data, 'ro')
plt.show()
The data is in a csv file and looks like this but far longer.
I2,V2,I2,V2,I2,V2
0,-0.5,0,-1,0,-0.9
2.00E-011,0.5,1.00E-010,0,3.50E-010,0.1
5.00E-011,1.5,3.00E-010,1,1.55E-009,1.1
Also when I run the assign data file I get this weird error.
SyntaxError: EOL while scanning string literal
Any help would be appreciated.
Upvotes: 0
Views: 1062
Reputation: 6128
I think that the problem comes from your header. Your header (first line) is a string and obviously, matplotlib can't plot this kind of data.
You have to make :
data = np.genfromtxt("/home/rex/Documents/ModLab/PhotoElec/Exp2Data.csv",
delimiter=',',
unpack=True,
names=True,
skip_header = 1)
# skip_header let to go directly to your data and pass the header
I didn't run the script but it should work ;)
Upvotes: 0
Reputation: 509
I think your problem is in the actual import - it may have been imported as a string, not a number.
I'd suggest using pandas to handle the import. If you're doing scientific computing, you'll find pandas very useful. Your problem then becomes:
import pandas
data = pandas.read_csv('Exp2Data.csv')
i2 = data.I2
v2 = data.V2
# ... plot as needed
There may also be ways for pandas to handle the plotting as well!
Upvotes: 1