# HG changeset patch # User nikcleju # Date 1326480266 0 # Node ID b4a0b4dfe206f708cd629f49761f5cf299445d88 # Parent 09651b934691de6e64a5eb7989c25b272cab872c utils.py: added function int_setticks() to set ticks and ticklabels diff -r 09651b934691 -r b4a0b4dfe206 utils.py --- 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