In [1]:
from matplotlib.mlab import PCA as mlabPCA
import h5py
from pylab import*
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d import proj3d

params = { 'figure.figsize' : [20, 20],
          'figure.dpi:' : 150,
          'figure.autolayout:' : True,
          'text.usetex' : True,
          'font.size' : 11,
          'font.family' : 'lmodern',
          'text.latex.unicode': True,
          'legend.fontsize' : 'medium',
          'legend.handlelength' : 2.2,
          'lines.linewidth' : 0.7,
          }
plt.rcParams.update(params)

In [2]:
h5_file = h5py.File("data/koendata.h5", 'r')

dataset_A = h5_file.get("/an0074")
dataset_B = h5_file.get("/an0075")

valueMatrices_A = []
valueMatrices_B = []

for day in dataset_A:
    group = day + "/valueMatrix"
    valueMatrices_A.append(dataset_A.get(group))
    
    
for day in dataset_B:
    group = day + "/valueMatrix"
    valueMatrices_B.append(dataset_B.get(group))

In [3]:
for index, matrix in enumerate(valueMatrices_A):
   if any(isnan(matrix)):
        print matrix.name
        print valueMatrices_A[index].shape
        badData = array(unique(where(isnan(matrix))[0]))
        matrix = delete(matrix, badData,0)
        valueMatrices_A[index] = matrix
        
        print valueMatrices_A[index].shape
        

for index, matrix in enumerate(valueMatrices_B):
   if any(isnan(matrix)):
        print matrix.name
        print valueMatrices_B[index].shape
        badData = array(unique(where(isnan(matrix))[0]))
        matrix = delete(matrix, badData,0)
        valueMatrices_B[index] = matrix
        print valueMatrices_B[index].shape


/an0074/2013_09_24/valueMatrix
(18987, 46)
(18824, 46)
/an0075/2013_10_01/valueMatrix
(28697, 50)
(28615, 50)

In [4]:
fig = plt.figure()
ax1 = fig.add_subplot(111, projection='3d')

day = 0
for matrix in valueMatrices_A:
    matrix = array(matrix)
    mlab_pca = mlabPCA(matrix)
    day +=1 
    
    ax1.plot(mlab_pca.Y[:,0],mlab_pca.Y[:,1],mlab_pca.Y[:,2], 'o', markersize=7, alpha=0.5, label = 'day: ' + str(day))
    ax1.legend()

fig = plt.figure()
ax2 = fig.add_subplot(111, projection='3d')
day = 0
for matrix in valueMatrices_B:
    matrix = array(matrix)
    mlab_pca = mlabPCA(matrix)
    day +=1 
    ax2.plot(mlab_pca.Y[:,0],mlab_pca.Y[:,1],mlab_pca.Y[:,2],  'o', markersize=7, alpha=0.5, label = 'day: ' + str(day))
    ax2.legend()



In [5]:
#%pylab qt
fig = plt.figure()
title('Animal A')
day = 0
for matrix in valueMatrices_A:
    matrix = array(matrix)
    mlab_pca = mlabPCA(matrix)
    day +=1
    ax= fig.add_subplot(3,5,day, projection='3d')
    ax.plot(mlab_pca.Y[:,0],mlab_pca.Y[:,1],mlab_pca.Y[:,2], 'o', markersize=7, alpha=0.5, label = 'day: ' + str(day))
    ax.legend()
    ax.set_xlim([-20., 20.])
    ax.set_ylim([-20., 20.])
    ax.set_zlim([-10., 10.])