Rex Yeigh Rex Yeigh - 7 months ago 106
Python Question

How do I import data in scientific notation for a plot?

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.

Answer

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!