PEATDB/plugins/PCA.py
def plotResults(self,evals,evecs,b,m):
        """Plot results to help visualize components"""
        data = numpy.array(m.matrix)
        labels = m.columnHeaders()
        plt.rc('font', family='monospace')

        #plot first 2 PCs in 3d score plot        
        '''x,y,z = b[:,0], b[:,1], b[:,2]
        f=plt.figure()
        ax = Axes3D(f)
        ax.scatter(x,y,zs=z,marker='o',lw=2,alpha=0.5,c='b',s=30)
        ax.set_xlabel('PC1')
        ax.set_ylabel('PC2')
        ax.set_zlabel('PC3')'''
        
        #f.subplots_adjust(hspace=1,wspace=1)
        
        f=plt.figure()
        i=1
        length = len(data[0])
        if length>6: length=6
        for i in range(0,length):
            ax=f.add_subplot(3,3,i+1)
            c=0
            lines=[]
            for v in zip(*data):     
                c+=1
                if c>10: break
                #v = [float(j)/(max(v)-min(v)) for j in v]               
                l=ax.plot(b[:,i],v,'x',mew=1,alpha=0.2)
                lines.append(l)
                ax.set_title('Ev%s' %str(i+1))
                
            i+=1    
        f.legend(lines,labels,loc='lower right')        
        ax=f.add_subplot(337)
        ind=numpy.array(range(len(evals)))
        ax.plot(ind,evals,'-o',lw=2)
        ax.set_xlabel('Eigenvalues')
        f.savefig('PCAresults.png')
        f.subplots_adjust(hspace=0.4,wspace=0.4)
        print 'Eigenvalues: ', evals
        print 'Eigenvectors: ', evecs
        plt.show()
        return
Plot results to help visualize components
Plot results to help visualize components
Plot results to help visualize components
def plotResults(self,evals,evecs,b,m):
        data = numpy.array(m.matrix)
        labels = m.columnHeaders()
        plt.rc('font', family='monospace')
        f=plt.figure()
        i=1
        length = len(data[0])
        if length>6: length=6
        for i in range(0,length):
            ax=f.add_subplot(3,3,i+1)
            c=0
            lines=[]
            for v in zip(*data):     
                c+=1
                if c>10: break
                l=ax.plot(b[:,i],v,'x',mew=1,alpha=0.2)
                lines.append(l)
                ax.set_title('Ev%s' %str(i+1))
            i+=1    
        f.legend(lines,labels,loc='lower right')        
        ax=f.add_subplot(337)
        ind=numpy.array(range(len(evals)))
        ax.plot(ind,evals,'-o',lw=2)
        ax.set_xlabel('Eigenvalues')
        f.savefig('PCAresults.png')
        f.subplots_adjust(hspace=0.4,wspace=0.4)
        print 'Eigenvalues: ', evals
        print 'Eigenvectors: ', evecs
        plt.show()
        return
def plotResults ( self , evals , evecs , b , m ) : data = numpy . array ( m . matrix ) labels = m . columnHeaders ( ) plt . rc ( 'font' , family = 'monospace' ) '''x,y,z = b[:,0], b[:,1], b[:,2]
        f=plt.figure()
        ax = Axes3D(f)
        ax.scatter(x,y,zs=z,marker='o',lw=2,alpha=0.5,c='b',s=30)
        ax.set_xlabel('PC1')
        ax.set_ylabel('PC2')
        ax.set_zlabel('PC3')''' f = plt . figure ( ) i = 1 length = len ( data [ 0 ] ) if length > 6 : length = 6 for i in range ( 0 , length ) : ax = f . add_subplot ( 3 , 3 , i + 1 ) c = 0 lines = [ ] for v in zip ( * data ) : c += 1 if c > 10 : break l = ax . plot ( b [ : , i ] , v , 'x' , mew = 1 , alpha = 0.2 ) lines . append ( l ) ax . set_title ( 'Ev%s' % str ( i + 1 ) ) i += 1 f . legend ( lines , labels , loc = 'lower right' ) ax = f . add_subplot ( 337 ) ind = numpy . array ( range ( len ( evals ) ) ) ax . plot ( ind , evals , '-o' , lw = 2 ) ax . set_xlabel ( 'Eigenvalues' ) f . savefig ( 'PCAresults.png' ) f . subplots_adjust ( hspace = 0.4 , wspace = 0.4 ) print 'Eigenvalues: ' , evals print 'Eigenvectors: ' , evecs plt . show ( ) return
Plot results to help visualize components
Plot results to help visualize components
"""Plot results to help visualize components""" #plot first 2 PCs in 3d score plot         '''x,y,z = b[:,0], b[:,1], b[:,2]
        f=plt.figure()
        ax = Axes3D(f)
        ax.scatter(x,y,zs=z,marker='o',lw=2,alpha=0.5,c='b',s=30)
        ax.set_xlabel('PC1')
        ax.set_ylabel('PC2')
        ax.set_zlabel('PC3')''' #f.subplots_adjust(hspace=1,wspace=1) #v = [float(j)/(max(v)-min(v)) for j in v]               
self
evals
evecs
b
m