Rex Yeigh Rex Yeigh - 2 years ago 242
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.plot(data, 'ro')

The data is in a csv file and looks like this but far longer.


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 Source

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!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download