changeset 7:b4a0b4dfe206

utils.py: added function int_setticks() to set ticks and ticklabels
author nikcleju
date Fri, 13 Jan 2012 18:44:26 +0000
parents 09651b934691
children 4d1bfd404f6a
files utils.py
diffstat 1 files changed, 29 insertions(+), 86 deletions(-) [+]
line wrap: on
line diff
--- a/utils.py	Fri Jan 13 15:56:33 2012 +0000
+++ b/utils.py	Fri Jan 13 18:44:26 2012 +0000
@@ -14,90 +14,6 @@
 # Sample call
 #utils.loadshowmatrices_multipixels('H:\\CS\\Python\\Results\\pt_std1\\approx_pt_std1.mat', dosave=True, saveplotbase='approx_pt_std1_',saveplotexts=('png','eps','pdf'))
 
-#def loadshowmatrices(filename, algonames = None):
-#    mdict = scipy.io.loadmat(filename)
-#    if algonames == None:
-#      algonames = mdict['algonames']
-#    
-#    for algonameobj in algonames:
-#        algoname = algonameobj[0][0]
-#        print algoname
-#        if mdict['meanmatrix'][algoname][0,0].ndim == 2:
-#            plt.figure()
-#            plt.imshow(mdict['meanmatrix'][algoname][0,0], cmap=cm.gray, interpolation='nearest',origin='lower')            
-#        elif mdict['meanmatrix'][algoname][0,0].ndim == 3:
-#            for matrix in mdict['meanmatrix'][algoname][0,0]:
-#                plt.figure()
-#                plt.imshow(matrix, cmap=cm.gray, interpolation='nearest',origin='lower')
-#    plt.show()
-#    print "Finished."
-#
-#
-#def loadsavematrices(filename, saveplotbase, saveplotexts, algonames = None):
-#    
-#    mdict = scipy.io.loadmat(filename)
-#    lambdas = mdict['lambdas']
-#
-#    if algonames is None:
-#      algonames = mdict['algonames']
-#    
-#    for algonameobj in algonames:
-#        algoname = algonameobj[0][0]
-#        print algoname
-#        if mdict['meanmatrix'][algoname][0,0].ndim == 2:
-#            plt.figure()
-#            plt.imshow(mdict['meanmatrix'][algoname][0,0], cmap=cm.gray, interpolation='nearest',origin='lower')
-#            for ext in saveplotexts:
-#              plt.savefig(saveplotbase + algoname + '.' + ext, bbox_inches='tight')
-#        elif mdict['meanmatrix'][algoname][0,0].ndim == 3:
-#            ilbd = 0
-#            for matrix in mdict['meanmatrix'][algoname][0,0]:
-#                plt.figure()
-#                plt.imshow(matrix, cmap=cm.gray, interpolation='nearest',origin='lower')
-#                for ext in saveplotexts:
-#                  plt.savefig(saveplotbase + algoname + ('_lbd%.0e' % lambdas[ilbd]) + '.' + ext, bbox_inches='tight')
-#                ilbd = ilbd + 1
-#    print "Finished."  
-    
-def loadmatrices(filename, algonames=None, doshow=True, dosave=False, saveplotbase=None, saveplotexts=None):
-    
-    if dosave and (saveplotbase is None or saveplotexts is None):
-      print('Error: please specify name and extensions for saving')
-      raise Exception('Name or extensions for saving not specified')
-    
-    mdict = scipy.io.loadmat(filename)
-
-    if dosave:
-      lambdas = mdict['lambdas']
-
-    if algonames is None:
-      algonames = mdict['algonames']
-    
-    for algonameobj in algonames:
-        algoname = algonameobj[0][0]
-        print algoname
-        if mdict['meanmatrix'][algoname][0,0].ndim == 2:
-            plt.figure()
-            plt.imshow(mdict['meanmatrix'][algoname][0,0], cmap=cm.gray, norm=mcolors.Normalize(0,1), interpolation='nearest',origin='lower')
-            if dosave:
-              for ext in saveplotexts:
-                plt.savefig(saveplotbase + algoname + '.' + ext, bbox_inches='tight')
-        elif mdict['meanmatrix'][algoname][0,0].ndim == 3:
-            if dosave:
-              ilbd = 0
-            for matrix in mdict['meanmatrix'][algoname][0,0]:
-                plt.figure()
-                plt.imshow(matrix, cmap=cm.gray, norm=mcolors.Normalize(0,1), interpolation='nearest',origin='lower')
-                if dosave:
-                  for ext in saveplotexts:
-                    plt.savefig(saveplotbase + algoname + ('_lbd%.0e' % lambdas[ilbd]) + '.' + ext, bbox_inches='tight')
-                  ilbd = ilbd + 1
-    
-    if doshow:
-      plt.show()
-    print "Finished."    
-
-    
 def loadshowmatrices_multipixels(filename, algonames = None, doshow=True, dosave=False, saveplotbase=None, saveplotexts=None):
   
     if dosave and (saveplotbase is None or saveplotexts is None):
@@ -149,7 +65,13 @@
                     
             plt.figure()
             #plt.imshow(mdict['meanmatrix'][algoname][0,0], cmap=cm.gray, interpolation='nearest',origin='lower')            
-            plt.imshow(bigmatrix, cmap=cm.gray, norm=mcolors.Normalize(0,1), interpolation='nearest',origin='lower')        
+            plt.imshow(bigmatrix, cmap=cm.gray, norm=mcolors.Normalize(0,1), interpolation='nearest',origin='lower')
+            #if algoname == 'GAP':
+            int_setticks()
+            #else:
+            #  plt.gca().get_xaxis().set_visible(False)
+            #  plt.gca().get_yaxis().set_visible(False)
+              
             if dosave:
               for ext in saveplotexts:
                 plt.savefig(saveplotbase + algoname + '.' + ext, bbox_inches='tight')            
@@ -187,6 +109,9 @@
                 plt.figure()
                 #plt.imshow(matrix, cmap=cm.gray, interpolation='nearest',origin='lower')
                 plt.imshow(bigmatrix, cmap=cm.gray, norm=mcolors.Normalize(0,1), interpolation='nearest',origin='lower')
+                plt.gca().get_xaxis().set_visible(False)
+                plt.gca().get_yaxis().set_visible(False)
+                #int_setticks()
                 if dosave:
                   for ext in saveplotexts:
                     plt.savefig(saveplotbase + algoname + ('_lbd%.0e' % lambdas[ilbd]) + '.' + ext, bbox_inches='tight')
@@ -228,4 +153,22 @@
         if j<cols-1 and matrix[i,j+1] < thresh:
           bigmatrix[i*N:i*N+N,j*N+N-border:j*N+N] = bordercolor  
   
-  return bigmatrix
\ No newline at end of file
+  return bigmatrix
+  
+def int_setticks():
+
+  ticks = [10, 94, 179]
+  ticklabels = ["0.05", "0.5", "0.95"]
+
+  ax = plt.gca()
+  ax.set_xticks(ticks)
+  ax.set_xticklabels(ticklabels)
+  ax.set_yticks(ticks)
+  ax.set_yticklabels(ticklabels)
+  
+  for label in ax.get_xticklabels():
+    label.set_fontsize(42) 
+  for label in ax.get_yticklabels():
+    label.set_fontsize(42)
+    
+  ax.set_xlabel('\delta')