In [15]:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

def read_file(f):
    h = open(f, "r")
    x = []
    y = []
    z = []
    for line in h.readlines():
        data = line.split(";")
        if (len(data) == 4):
            try:
                x.append(float(data[0]))
                y.append(float(data[1]))
                z.append(float(data[2]))
            except:
                continue
            
    return [x,y,z]
        
def norm(d_in):
    x_min = min(d_in)
    x_max = max(d_in)

    offset = (x_max + x_min) / 2
    sens = (x_min - x_max) / 2
    
    print x_min, x_max, offset, sens
    
    d_out = []
    for y in d_in:
        d_out.append((y - offset) / sens)
        
    return d_out
    
    
data = read_file("mag_data1.csv")




fig = plt.figure(1, figsize=(15,13))
axs = fig.add_subplot(111, projection='3d')

# axis = axs.plot(data[0], data[1], "r-", zs = data[2])
plt.hold(1)

print "x_min, x_max, offset, sens"

print "x",
data[0] = norm(data[0])
print "y",
data[1] = norm(data[1])
print "z",
data[2] = norm(data[2])
print

axs.plot(data[0], data[1], "r-", zs = data[2])
axs.set_autoscale_on(True)
plt.show()


x_min, x_max, offset, sens
x -2010.0 2962.0 476.0 -2486.0
y -1315.0 3674.0 1179.5 -2494.5
z -1301.0 3583.0 1141.0 -2442.0


In [ ]: